The Sudoers File#
Let's add superman
to the "sudoers file" mentioned in the error above. We're going to grant them full access like our original user (michael
in my case.)
I'm going to edit a file called /etc/sudoers
: sudo visudo
I get these contents, by default, on my systems:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
We won't go into too much detail on this file - because that'll be a project for you - but we can see two important lines: 20
and 26
.
Line 20
lets the root
use the sudo
command to do anything. The complex terminology ALL=(ALL:ALL) ALL
is left for you to research, but essentially it means, "Let the user do anything." In the case of root
, it's simply here as an example entry because the root
user doesn't need to use sudo
to do anything.
Line 26
is interesting, because it's saying that a group (%
) called sudo
(%sudo
) can also do anything they want via the sudo
command. We'll come back to this later.
Under line 20
, add another, identical "user privilege specification" line:
1 |
|
Then save (Ctrl+O) the file and exit (Ctrl+X) the editor. Now let's try logging in as the superman
user and try to add spiderman
again:
1 2 3 4 5 6 7 8 9 10 |
|
I was able to create our new superhero, spiderman
, as a user on our system. I can even delete him:
1 2 3 4 |
|
So we added superman
to the sudoers
file, allowing them to use sudo
to execute privileged commands. There is an easier way of achieving the same goal, though. Let's use superman
's new privileges to remove ourselves from the sudoers
file: sudo visudo
.
Remove the line we added previously, save and exit the file (Ctrl+O, Ctrl+X). Now try to do sudo visudo
again.
1 2 |
|
So, we've stripped our own privileges. That was silly. Let's get our original super user to add them again, but a bit differently this time.