- In this video, we are going to explore the use of su.
Su is for switch user.
It allows you to open a shell as any specific user.
For instance, if you use su Lisa,
then it'll prompt for a password
and open a shell as user Lisa.
Notice that it will only prompt for a password.
If you are doing this as an ordinary user,
user root can open a shell as any user
without entering a password.
If you just use su, then it'll prompt for the root password
and open a root shell.
You use su without any further arguments to open a subshell.
Subshell means that not all environments
are set as the target user.
If you use su -, you open a login shell.
In a login shell, environment variables
are set as the target user.
The result is that su - is the better solution
because it guarantees
that you are in the appropriate environment.
The user root can use su to become any other user
without entering a password.
And a regular users can use su as well,
but they need to enter the target user password.
Let's go check this out.
So as you can see, I'm in a shell, su is a student.
And in the shell su student, I can type su -
and it'll prompt for a password.
And right now, I'm in a root shell.
You can recognize the root shell
because I have a root@centos with a hash
and that is showing that I'm in a root shell.
So if I type whoami, for instance,
then I can see that I'm root.
This is one way to open a temporary root shell.
Disadvantages that in order to use su -,
you need to know the root password.
Now as a root, I can use su Linda
to open a shell as user Linda.
As you can see, I'm not prompted
for any password whatsoever.
To exit from the shell you type exit.
I just did, and that brings me back to the root shell.
And if I type exit again, then I'm back in my student shell.
Now I want to show you what is happening
if I use su - linda.
Again, I would advise you always to use su -
because really you want to set the environment
the right way.
So su - linda doing what,
it's prompting for the password Linda.
And you know what?
Linda doesn't have a password
so I can try whatever I want.
This is not going to work.
Now, let's also do this on Ubuntu.
So here we go.
I am user student right now,
and what is happening if I use su -,
well it's prompting for the root password.
And what is the root password?
Well, that is exactly the problem.
The root user on Ubuntu does not have a password.
Su and su - straight like this on Ubuntu
is not a good option.
On Ubuntu, you go for sudo.
And that is what is going to be discussed in the next video.