- The preferred way to run administrative tasks
is by using sudo.
That is because sudo is more sophisticated.
It allows you to grant users privileges to
learn specific tasks or all tasks with elevated permissions.
In admin, it's either you are root, or you are not,
and in sudo, you can go for the solution in the middle.
You can create a configuration where a user
just has access to a limited couple of tasks.
The default "admin" user has sudo privileges by default.
But what is this default "admin" user?
Well, this default "admin" user
is a user that may be created
while installing your Linux distribution.
Depends on your installation options.
So watch your installation options to make sure
that you do have an admin user, but normally you should.
On Red Hat, you will be an admin user
if you are a member of the group wheel.
And notice that on Red Hat,
when a root user is created with a password,
there is no default "admin" user.
You need to specifically grant administrator privileges
to a user account while installing
if you wanna have this default "admin" user.
I will show you in one of the next lessons managing users,
how you can create admin users later.
It's not that difficult, but let's not do that now.
On Ubuntu, the default "admin" user
is a member of the group sudo.
As a sudo enabled user,
you use sudo followed by the command that you want to run
with the escalated privileges.
Or alternatively, you can use sudo - i to open a root shell,
which is not recommended, but it's an option.
Let me show you sudo.
So the first thing to investigate sudo is the id command.
What is this command?
Well, this command is showing the groups
that you are currently a member of.
I'm old centos here, and as you can see,
I'm a member of the group wheel,
which means that I can run tasks with sudo privileges.
Just to make sure that you get it,
I'm using ls - l /root
And what is it giving me?
That's giving me permission denied.
I'm using the up arrow to repeat the last command.
And now I'm using control a
to go to the start of the command line,
followed by sudo ls - l.
And I'm prompted for the root password, that is okay.
Here we go.
I can see the contents of the root directory at this point.
Now the thing is that if you use sudo
in front of an ls command,
then only the ls command is executed
with administrative privileges.
And right now I'm back in my ordinary user shell.
And that's exact exactly how I want it to be.
Alternatively, you can use sudo - i,
which is giving you access to a complete root shell.
Not recommended.
But if it's not recommended why would you wanna do it?
Well, sometimes you need to do administration.
And if you are going to work as an administrator,
then you might want to be in a sudo shell
for the entire day and then this is convenient.
At the end of being in a sudo shell,
you need to type exit to get out of there.
An alternative way is sudo su -
Now, what is the difference?
Well, sudo su - is using the su mechanism
to open a root shell,
and effectively the result is the same.
Now, is there any difference on Ubuntu?
Let's go check it out.
On Ubuntu, if I type id,
then I can see that the user is a member of the adm group.
And the user is also a member of the sudo group.
And basically both of them are granting sudo privileges.
So sudo ls - l /root
is prompting for the password, as expected.
I'm entering the password.
And I can see the contents of the directory /root.
And also sudo - i works on Ubuntu
and sudo su - works on Ubuntu.
So between the Linux distributions,
there is no real difference in using sudo.
The only difference is in how you are making sure
that the user is becoming administrative user
but that's more about user groups,
a topic that we will talk about later.