Ubuntu: difference between sudo su - and su - [duplicate]



Question:

I have tried in Google but couldn't get exactly what I need.

Could somebody explain the difference between sudo su - & su -

Thank you.


Solution:1

From man page su

-, -l, --login Provide an environment similar to what the user would expect had the user logged in directly.

When - is used, it must be specified as the last su option. The other forms (-l and --login) do not have this restriction.

su allows you to log in as a specific user. You'd get an interactive shell that way. When you use su - you get a login shell for that user. That's the main difference. For differences between login and non-login shell, check this answer

Now in case of sudo su -, which acts pretty much the same as sudo su or sudo -i you log in as root, but authenticate with your sudo password.


Solution:2

The difference between sudo su - and su - is this:

With sudo su - you will be asked to authenticate with your user password (assuming you have sudo privileges). If you have sudo privileges with no password, then you will not be prompted for a password and instead will be logged into root immediately.

With su - you will be asked to authenticate with the root password. This only works if you have set the root password.

In terms of functionality, you can use either one for anything and they will do it the same, but sudo su - can be easier to get into if you have sudo privileges with NOPASSWD. Please note that having sudo with NOPASSWD enabled is a great security risk on any user that can be accessed over SSH or telnet or any remote login protocol.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »