我正在运行 RHEL 7.3,但在其他 Linux 系统上该过程可能类似。
我已以 root 身份登录。我有一个名为的文件openrc
,里面全是这样的行export OS_IDENTITY_API_VERSION=3
。我想将此文件移动到某个地方,以便当另一个用户使用 SSH 登录时自动加载它。阅读相关主题后,我尝试以 root 用户身份添加它,但这似乎只会为 root 用户添加这些值。当我以另一个用户身份登录时,比如“admin01”,这些值不会被加载。
echo source /home/admin01/openrc>>~/.bash_profile
我也尝试将此文件移动到 /etc/profile.d,但它似乎也仅为 root 加载,而不为任何其他登录用户加载。有人可以解释一下发生了什么吗?
cp /home/admin01/openrc /etc/profile.d/openrc.sh
有/etc/profile
这样的警告;
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
答案1
如果您也需要为守护进程定义变量,请命名它/etc/profile.d/openrc.sh
或使用它。/etc/environment
以下是示例(CentOS 7):
# ls -lhaZ /etc/profile.d/
[...]
-rw-r--r--. root root unconfined_u:object_r:bin_t:s0 /etc/profile.d/foo.sh
内容:
export HISTSIZE=10000
export HISTFILE=~/.bash_history
export HISTCONTROL=ignoredups:ignorespace:erasedups
export HISTTIMEFORMAT="%y-%m-%d %H:%M "
以非root用户身份登录:
$ set | grep HIST
HISTCONTROL=ignoredups:ignorespace:erasedups
HISTFILE=/home/user/.bash_history
HISTFILESIZE=10000
HISTSIZE=10000
HISTTIMEFORMAT='%y-%m-%d %H:%M '
使用/etc/environment
,将不带 的行放入 /etc/environment 中export
。
/etc/environment
请记住,当您不使用 bash 或不使用 bash 作为登录 shell 时,您可能需要坚持:
答案2
请注意,对 /etc/profile 和 /etc/profile.d 所做的所有更改都将应用于登录系统的每个用户。由于我预感到此 openrc 文件具有身份验证凭据,因此您必须确保确实希望将其应用于每个用户。如果您只希望将其应用于某些用户,您可以将文件复制到他们的主文件夹,并将其包含在他们的 ~/.profile 中,并添加一行source ~/openrc