I see both does the same thing and both end me up in the same directory.So is it really the same or there is a difference?
Also doing su and su - makes me root user in both the cases.So how is it even benficial?
I see both does the same thing and both end me up in the same directory.So is it really the same or there is a difference?
Also doing su and su - makes me root user in both the cases.So how is it even benficial?
There are differences between them:
First of all using su username
you have to provide the password of "username" to be able to switch into its account while with sudo su - username
for a second with your own password you will become root, then without using any other password you are running the su - uesrname
to switch into the "username".
The other difference is using -
with su
it will switches to the user while running a login shell, without the -
you will get a non-login shell.
su username
:
.profile
will not be sourced).sudo su - username
su
command as root (if you're permitted to)It's not a good idea to share a single password between users, so it's best to not use su
at all, instead we can use sudo
, also there is no need to run something like:
sudo su - username
we can setup our /etc/sudoers
file then use something like:
sudo -i -u username
If you have to use su
, then always use it like su -
to make sure everything is sourced as it should be and nothing has been compromised with.