Today, we're going to go over
Assuming Superuser Privileges.
Now, in IT security it's best practice
to give users the least amount of privilege.
With Linux the root administrator has ultimate power.
It can execute any function on any file.
Now, that's not best practice.
So, the best thing to do whenever you log on to any system,
is log into a standard user account,
and then elevate your privileges as necessary.
Now, one great way of accomplishing this,
is using the pseudo command.
Being root should be used sparingly,
because again, anything you type can be executed.
And there's some functions
and there's some commands that you can do,
to create inadvertent causes to the systems,
that could be devastating and irreversible.
So we want to make sure that we're using
these commands very sparingly,
and with forethought.
All right.
First things first.
We're going to log in as a root user.
Going to prompt us for a password here.
And now we're executing as the root privileged user.
Now, another way of doing this,
if you want to exit out of here, log out.
Is to just do su - without any options after the dash.
It assumes that you want to do root.
So that's just a faster way to do it,
if you want to do it that way.
Now, we're going to use the ID command to verify our privilege.
Now for a super user or a root,
the user ID, UID is always zero.
So that's one quick way to know exactly who you are,
if you're going to use this ID command.
I want to make sure,
we're going to check our present working directory.
All right.
Typically once you switch to user
you're executing out of the root directory.
So, something to keep note of.
Now, the pseudo files allows us to
tailor the type of privileges an account can have.
Typically you can use Vim or Nano
for any type of text editing.
But specifically for sudoers,
just to make sure there's no errors,
you can only use the Visudo.
So, we're going to use testadmin in this example.
So we're going to switch to him really quick.
Now we're going to try to run this command
the shut down command,
just to see the effects of the sudoers file.
Try to reboot,
that's what the -r stands for, in 15 minutes.
Now we see the output,
it says the "testadmin is not in the sudoers file.
This incident will be reported."
So that means this user does not have the correct privileges
to execute this to command.
So what we're going to do is modify this.
We're going to switch to the root.
And now let's use the
Visudo.
This gets us into the sudoers file so we can edit it.
We can go to the bottom,
and use the end key.
It's at the end of the line.
And now we're going to go use O,
to start the insertion.
We use testadmin.
And we're going to allow,
that's what this ALL stands for,
all provisions.
And just for convenience,
we're going to add the NOPASSWD.
Cause typically every time you use the sudo command
it requires you to enter your password.
This is not recommended,
but for the sake of this example
it makes things a lot easier,
or more efficient.
But for security it's a no go.
Okay here.
Right, quit.
Now let's switch it back to at testadmin again,
and let's try to run that command.
And this is reboot in 15 minutes.
Now we see we're able to successfully execute that command.
So the sudoer file again,
allows us to add users to their file.
So the system knows,
hey they can perform root level privileges.
And of course you can tailor which privileges
and which commands to be executed.
But for the example we just set it to all privileges.
All right, I'll exit out of this.
And so now we want to actually cancel this reboot,
c.
So now that was successfully canceled.