/etc/profile
のPATH
にディレクトリを追加しました。これは私のユーザーアカウントでは機能しますが、rootでは機能しません。 /root/.bashrc
に追加するのは簡単ですが、何が問題なのかを理解したいと思います。これはほとんど変更されていないDebian6なので、私の変更でうまくいくと思います。
これが私の/etc/profile
です:
# /etc/profile: system-wide .profile file for the Bourne Shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/lib/distcc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/lib/distcc/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH
if [ "$PS1" ]; then
if [ "$BASH" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
編集:私が追加したパスはdistcc-stuff
です。 echo $PATH
が教えてくれることは次のとおりです。
$ echo $PATH
/usr/lib/distcc/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/etc/profile
をロードするには、ログインシェルを実行する必要があります(または非対話型シェルを実行しますが、それは必要なことではありません)。
使用する
su - username
またはルートの場合
su -
これをする。
-
は-l
または--login
と同じであり、シェルをログインシェルにします。
ログインシェルが必要であり、Sudoを使用して作成できます。
Sudo bash --login <command>
ログインシェルをシミュレートする必要があります。これは、-i
を使用してSudoで実行できます。
Sudo -i <command>
man Sudo
から:
-i [command]
The -i (simulate initial login) option runs the Shell specified by the password
database entry of the target user as a login Shell. This means that login-spe‐
cific resource files such as .profile or .login will be read by the Shell. If a
command is specified, it is passed to the Shell for execution via the Shell's -c
option. If no command is specified, an interactive Shell is executed. Sudo
attempts to change to that user's home directory before running the Shell. The
security policy shall initialize the environment to a minimal set of variables,
similar to what is present when a user logs in. The Command Environment section
in the sudoers(5) manual documents how the -i option affects the environment in
which a command is run when the sudoers policy is in use.