su - user Vs sudo su - user

Just repeating both @dr01 and @OneK's answers because they are both missing some fine details:

  • su - username - Asks the system to start a new login session for the specified user. The system will require the password for the user "username" (even if its the same as the current user).
  • sudo su - username will do the same, but first ask the system to be elevated to super user mode, after which su will not ask for "username"'s password because a super user is allowed to change into any other user without knowing their password. That being said, sudo in itself enforces security by by checking the /etc/sudoers file to make sure the current user is allowed to gain super user permissions,and possibly verifying the current user's password.

I would also like to comment that to gain a super user login session, please use sudo -i (or sudo -s) as sudo su - is just silly: its asking sudo to give super user permissions to su so that su can start a login shell for the super user - when sudo can achieve the same result better it by itself.


Having superuser rights, sudo su - username will log you in (in a login shell) as $username without asking for a password, while su - username will ask for the password of $username.


sudo su - username does the same as su - username: runs a login shell as username.

su - username run as root and sudo su - username do not require to know username's password (as they are run with elevated privileges), while su - username run as a normal user requires to know it.

Tags:

Linux

Sudo

Su

Users