我正在寻找正确的位置来保存要为所有用户运行的脚本,包括根用户。
我知道向/etc/profile
文件添加内容或在/etc/profile.d/
文件夹中创建脚本对于任何登录的用户都有效,但我希望这些脚本也能为根用户运行。
我需要把它们放在哪里?
答案1
在与一些专家交谈后,具体针对这个问题:为所有用户在 shell 登录时运行脚本有人告诉我阅读sudo caveat
下面链接的部分:
https://help.ubuntu.com/community/EnvironmentVariables#sudo_caveat
答案如下:
sudo caveat
Any variables added to these locations will not be reflected when invoking them
with a sudo command, as sudo has a default policy of resetting the Environment and
setting a secure path (this behavior is defined in /etc/sudoers). As a workaround,
you can use sudo su that will provide a shell with root privileges but retaining
any modified PATH variables. Alternatively you can setup sudo not to reset certain
environment variables by adding some explicit environment settings to keep in
/etc/sudoers:
运行sudo visudo
并将以下内容添加到底部:
Defaults env_keep += "http_proxy SOMEOTHERVARIABLES ANOTHERVARIABLE ETC"