Both these ways are polluted by the environment. This is also why sudo su and sudo -s are crappy ways of getting a root shell. home/muru /home/muru/bin:/home/muru/devel/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games To get the true result, I will run my shell as a login shell: # ssh '$SHELL -ilc "echo \$HOME \$PATH"' home/muru /home/muru/devel/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/gamesĮven with SSH, if you run a command instead of starting a shell, a login shell won't be run (note the absence of ~/bin in the SSH test, which is present in su - and sudo -i). root /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin home/muru /home/muru/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin To provide sudo access, the user has to be added to the sudo group. Typically, the sudo command is used to quickly run an administrative command, then return to the user account’s regular permissions. home/muru /home/muru/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games The sudo command grants a one-time or limited-time access to root functionality. # su - muru -c 'sh -c "echo $HOME $PATH"' home/muru /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games su - causes the user to run a login shell aka bash -login the same as if the user had logged in as the root from the login prompt and sudo su - is the same as sudo su - root specifying root is redundant. To start a login shell, run either of: su - Įxample: # su muru -c 'sh -c "echo $HOME $PATH"' This is a big one, since ~/.pam_environment is the shell-independent place for environment variables, and it is applied if you login from the GUI, the TTY or SSH. This means SSH loads ~/.pam_environment, but su doesn't. Whereas /etc/pam.d/su has: session required pam_env.so readenv=1 envfile=/etc/default/locale For example, /etc/pam.d/ssh has: session required pam_env.so user_readenv=1 envfile=/etc/default/locale bashrc script will be run before executing the su - root command. there might be different settings for different users in SSH configuration. sudo su lauches su directly with super user privileges, while sudo bash lauches the shell first and then executes the command with bash -c./etc/profile and /etc/profile.d/* may apply settings differently for different users (not by default, though).even if you start a login shell, different changes were made in root's ~/.profile, which might pollute the user's environment.So changes made in ~/.profile won't take effect. In particular, this means that the ~/.profile (or similar file) for that user is not sourced.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |