3

It might be a duplicate and I'm pretty sure I already show an answer to that somewhere, but I wondered what are the difference in term of right and variable and other stuff between sudo -s and sudo su -.
As far as I'm concern they both open a root shell where I can do whatever I want but I wondered if I could experience some differences one day.

Also this question on askUbuntu does not address my concerns

  • May I redirect you to my answer in askubuntu: askubuntu.com/a/376386/185729 – chaos Jul 22 '14 at 8:53
  • @chaos you may though it's good pratice to answer directly instead of redirecting to a ressource that might get modify any time :/ – Kiwy Jul 22 '14 at 8:55
  • you are right, i wrote an answer. – chaos Jul 22 '14 at 9:07
  • See also su vs sudo -s vs sudo bash which covers sudo -i and sudo -s. – Gilles Jul 22 '14 at 23:17
5

sudo -s

Reads the $SHELL variable and executes the content. If $SHELL contains /bin/bash it invokes sudo /bin/bash. So, /bin/bash is started as non-login shell so all the dot-files are not executed, but bash itself reads .bashrc of the calling user. Your environment stays the same. Your home will not be root's home. So you are root, but in the environment of the calling user.

sudo su -

su - is invoked by sudo. Unlike sudo su (withput the dash), the shell is called as a login shell, so /etc/profile, .profile and .bashrc are executed and you will find yourself in root's home directory with root's environment.

Sources:

  • I was sure they were some differences – Kiwy Jul 22 '14 at 9:36
  • The later (su - <acct> also ensures that you parse the accounts environment files. – sleepyweasel Jan 24 '17 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.