Linux – What’s the difference between the commands “su -s” and “sudo -s”

linuxsudounix

What is the difference between the two super user commands, su -s and sudo -s?

They both give a shell with access to the superuser account.

Best Answer

In practice, they will both make you the superuser. However, they do slightly different things, in slightly different ways.

First, su - switches you to a login shell, whereas sudo -s does not. In practice, this often means that your environment variables will not be switch to root's for sudo -s. Note that you can run just su to not get a login shell, or sudo -i to get a login shell [not in all versions].

Secondly, su and su - switch to a new user by asking you to authenticate as the new user. sudo -s and sudo -i (and just regular sudo foo) let you run a command for which you're pre-authorized [see /etc/sudoers], possibly by asking you to confirm your current ID.

If you want to be really cute, you can also run sudo su -, which will request to login as root (su -) run by the root user (the sudo part).

If the root user is locked (such as on Ubuntu), you will not be able to login as root using su. In this case, you'll need to use sudo -s or sudo -i