运行 -E 而不使用 sudo

运行 -E 而不使用 sudo

sudo -E bash -有没有不用命令就可以运行的方法sudo

我有一条命令curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -,我想在不存在的 Ubuntu 容器内运行sudo它。通过使用 Docker 运行它,我提供了 Docker 参数-u root:sudo,以便里面的所有内容都以 root 身份执行。

但是命令sudo -E bash -失败,因为sudo不存在。有没有办法直接运行-E bash -

答案1

-E是命令的一个选项sudo,而不是使用提升权限运行的实际命令的一部分。

man sudo

 -E, --preserve-env
             Indicates to the security policy that the user wishes to pre‐
             serve their existing environment variables.  The security
             policy may return an error if the user does not have permis‐
             sion to preserve the environment.

因此,由于您根本不使用sudo,因此环境无论如何都不会被修改。您不需要用任何东西替换此选项。只需

curl -sL https://deb.nodesource.com/setup_13.x | bash

(顺便说一下,后面-的参数bash没有效果,您也可以省略它。)

然而,从安全性角度考虑,以 root 身份直接运行从在线来源获取的未经验证的代码是否可取又是另一个问题……

相关内容