繁体   English   中英

安全地提供一线bash安装脚本

[英]Securely provide a one-liner bash install script

我喜欢提供单行的bash安装脚本,看起来像这样:

curl https://gist.githubusercontent.com/.../raw/install.sh | bash

甚至

curl http://tinyurl.com/installmything | bash

但这对于不信任我的人来说显然是巨大的安全风险。

有什么方便,简单的方法可以:

  1. 让用户在脚本运行之前对其进行查看,
  2. 仍然只需要一个复制粘贴操作
  3. 不太累吗

例如,我可以像这样提供单线:

wget https://gist.githubusercontent.com/.../installthing.sh ; cat installthing.sh ; read -p "Type YES to continue: " X && [ $X = "YES" ] && bash installthing.sh

那没有繁琐的要求。 还有更好的方法吗?

有两种类型的人不信任您:

  1. 谁知道bash:这些人仍然会下载您的脚本并查看其内容。 他们知道什么curl ... | bash curl ... | bash会执行,他们不会执行该命令。

  2. 谁不了解bash:即使向这些人展示源代码,他们也将无法做任何事情。 他们将无法决定该代码是否存在安全风险。

因此,我认为不需要在执行之前让用户查看脚本的内容。 但是,如果仍然需要,则可以例如运行脚本,但在执行真实代码之前询问用户。 就像是:

#!/bin/bash

read -p "Do you wish to see the content of this script before execution?" -n 1 -r
echo

if [[ $REPLY =~ ^[Yy]$ ]]
then
  tail -n +20 "$0"

  echo
  read -p "Continue? " -n 1 -r
  echo

  if [[ $REPLY =~ ^[Nn]$ ]]
  then
    exit
  fi
fi

echo "INSTALL"

这样,您可以继续使用:

curl https://gist.githubusercontent.com/.../raw/install.sh | bash

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM