firstly, look at the snippet below:
$ ssh -i ~/.ssh/ubuntu.pem ubuntu@127.0.0.1
ubuntu@kingdom:~$ echo $PATH | tr ':' '\n' | grep sbin
/usr/local/sbin
/usr/sbin
/sbin
ubuntu@kingdom:~$ sudo su -l ubuntu
ubuntu@kingdom:~$ echo $PATH | tr ':' '\n' | grep sbin
ubuntu@kingdom:~$
i have modified /etc/profile
, /etc/bash.bashrc
, /home/ubuntu/.profile
and /home/ubuntu/.bashrc
(the ubuntu
user has no other profile and bash configuration) to print the PATH
in the beginning and the end of the file.
now i can see that the problem occurs on the second login:
$ ssh -i ~/.ssh/ubuntu.pem ubuntu@127.0.0.1
/etc/profile: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
/etc/bash.bashrc: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
/etc/bash.bashrc: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
/etc/profile: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
/home/ubuntu/.profile: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
/home/ubuntu/.bashrc: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
/home/ubuntu/.bashrc: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
/home/ubuntu/.profile: /home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
ubuntu@kingdom:~$ sudo su -l ubuntu
/etc/profile: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
/etc/bash.bashrc: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
/etc/bash.bashrc: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
/etc/profile: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
/home/ubuntu/.profile: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
/home/ubuntu/.bashrc: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
/home/ubuntu/.bashrc: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
/home/ubuntu/.profile: /home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
it felt like it has something to do with the sudo
command. so i even tried to add !reset_env
to /etc/sudoers
, but it does not seem to solve the problem.
how can i use sudo su -l ubuntu
while preserving the environment variables (without any extra arguments to sudo
command) that ubuntu
user had before the sudo su -l
clarification:
i would like to get the same output for echo $PATH | tr ':' '\n' | grep sbin
before and after sudo su -l ubuntu
. right now, this is not the case:
$ ssh -i ~/.ssh/ubuntu.pem ubuntu@127.0.0.1
ubuntu@kingdom:~$ echo $PATH | tr ':' '\n' | grep sbin
/usr/local/sbin
/usr/sbin
/sbin
ubuntu@kingdom:~$ sudo su -l ubuntu
ubuntu@kingdom:~$ echo $PATH | tr ':' '\n' | grep sbin
ubuntu@kingdom:~$
sudo -i
. IMO the best method is to properly configure root's path / environmental variables rather than import them. See https://help.ubuntu.com/community/RootSudo#Special_notes_on_sudo_and_shells – Panther Nov 29 '17 at 15:17sudo su
is working as expected. I can not tell what your question is other than how do you set environmental variables both as a user and as root. – Panther Nov 29 '17 at 16:50PATH
is changing when usingsudo su -l ubuntu
and why is it different login than ssh login? – Mr. Nov 30 '17 at 07:30sudo su
to start a root shell, but to start a login shell for another user,ubuntu
. For some reason, usingsudo
tosu
to this user changes the PATH. When they SSH to that user account on localhost they get a different PATH variable, the one they want. They don't want to change root's environment. But it might have something to do withsudo
'ssecure_path
. MrRoth, how did you get the output for the config files after the login commands? I don't understand that... – Zanna Nov 30 '17 at 08:35sudo su -l ubuntu
, so my interest is low. If you look at the mechanics of login and sudo and su you will likely sort it out. – Panther Nov 30 '17 at 13:52