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 home/muru /home/muru/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games # 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 To start a login shell, run either of: su - Įxample: # su muru -c 'sh -c "echo $HOME $PATH"' This will tell the system to switch (and essentially log out of) the current user to the one specified. You can switch to any user by typing su and adding a username after it. 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. Content su su -c sudo su sudo -i sudo -s Frequently Asked Questions su The su command substitutes the current user for root in the current shell. ‘su’ Vs ‘sudo’ ‘su‘ forces you to share your root password to other users whereas ‘sudo‘ makes it possible to execute system commands without root password. This means SSH loads ~/.pam_environment, but su doesn't. NOTE This article is more applicable to Ubuntu based distributions, but also applicable to most of the popular Linux distributions. 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 there might be different settings for different users in SSH configuration./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 |