Let'S talk about sudo, because sudo is a more sophisticated way to grant
users privileges to run specific tasks or all tasks with elevated permissions.
The default user is an administrator user, and that user has sudo privileges by default.
This default user is the user that you would normally create when you install your distribution
on red hat. This user has sudo privileges because it's a member of the group wheel.
And when on red hat, you create a root user with a
password, then you should know there is no default admin user.
On Ubuntu, it's easier. The root user never has a password by default, so you get a
default administrative user who is administrative user because this user is a member of the group sudo.
As a sudo enabled user, you can use sudo command to run the command with escalated privileges, or
you can use sudo I to open a root shell. That's not really recommended, but sometimes it's convenient
if you know beforehand that there are multiple commands that you need to run with administrative privileges.
Let me show you.
So, to start with, I'm using LS l root. That's my favorite sudo test. What do you think? Is this going to work?
It doesn't, because I'm not using sudo to use my sudo superpowers. I need to
start this command using sudo. So sudo LS l root that is actually working.
So I'm entering the password that is the password for my current user account, and that is
enabling my sudo powers. Now, the funny fact is that I won't have to enter my password
for the next five minutes. So if I would use sudo password wdlinda to set a password
for user linda, then it's not prompting for a password. Well, it's prompting for a password.
But that's because I'm using the passwd command to set the password I don't have to authenticate again.
That's because when you use sudo, an authentication token is generated after you have entered the password Based on
that authentication token, you can continue using sudo without re entering the password for the next five minutes.
Now, let me also show you sudo I and sudo I is opening a root shell. As you can see,
I'm now root at linfen and the hash in my prompt is also indicating that I'm in a root shell.
Once you are done in your root shell, don't forget to type exit to get back to your normal operational environment.
There's a few more things that we need to discuss. Let's get back to the slides.
This is about using the right shell.
Let's say you want to use sudo echo hello greater than great then var log messages.
Now the thing is that that is not working because the greater than greater than is interpreted by the current shell.
That goes for all the shell metacharacters like redirects, like pipes and more. If you want to
use them in sudo command then this is how you use sudo sh c and then between
double quotes you have the entire command that you want to run. Let me show you.
So to start it sudo echo hello great then great then var log messages
is giving a permission denied and that's surprising but that's because of interpretation of
the current shell. So if we change that to sudo sh c and we
put the entire command between double quotes then suddenly it does work.
That is nice to remember. If ever you use shell metacharacters in your sudo.