Systemd Command (Demo)

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
Video Transcription
00:00
>> Hey there, Cybrarians.
00:00
Welcome back to the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Gills.
00:00
In today's lesson, we're going
00:00
to talk about the systemd commands.
00:00
Upon completion of this lesson,
00:00
you're going to be able to understand the purpose of
00:00
the systemctl command and then use
00:00
the systemctl command to manage
00:00
services and configure services to boot automatically.
00:00
Let's get after it with some demo time.
00:00
Here we are in our demo environment in Ubuntu.
00:00
What we're going to do here today
00:00
is we're going to start working with the systemctl.
00:00
Now the systemctl command is
00:00
primarily used to manage services,
00:00
so let's run some of those commands.
00:00
We're going to start out with systemctl,
00:00
and then we're going to say that we want
00:00
the status of a service.
00:00
We can get the status of, let's say, ssh.
00:00
Then we can see that the service status
00:00
of this is active running.
00:00
We can also see that it's enabled at boot.
00:00
We can see it's enabled right
00:00
here in terms of the loaded status.
00:00
If we wanted to restart the service, we could do that.
00:00
We're going to do this with a sudo command so that we
00:00
can do this without having to
00:00
constantly type the password.
00:00
We're going to say restart instead of status.
00:00
Now it's going to restart the service.
00:00
When we run systemctl status,
00:00
we see that it is still
00:00
running and we're good to go there.
00:00
That's been started. We see that it got
00:00
restarted a second ago. We're good to go.
00:00
Now what we can also do is we can stop the service.
00:00
We can stop it from running with the systemctl stop.
00:00
We're going to use sudo to become root
00:00
temporarily to do that. There we go.
00:00
Now if we run the systemctl status on ssh again,
00:00
we see that it's inactive or
00:00
dead instead of active and running.
00:00
That just means that the service has stopped.
00:00
Now what we do still see here though,
00:00
is that the service is enabled and
00:00
the systemctl command can also be
00:00
used to manage whether or not a service starts at boot,
00:00
whether it's enabled or disabled.
00:00
Ssh is enabled, so let's disable it.
00:00
We're going to go ahead and do sudo systemctl
00:00
disable ssh.
00:00
Note that when we disable this,
00:00
is actually removing links here.
00:00
It just basically is pointing to
00:00
the multiuser target wants ssh service.
00:00
Basically, what happens is that when we boot into
00:00
this multiuser target and
00:00
we'll talk about targets later,
00:00
there's a link there that says, hey,
00:00
you also need to boot up the ssh service on start.
00:00
That's really how a systemd initialization
00:00
understands what services need to
00:00
come up as child processes,
00:00
which we talked about in the previous lesson.
00:00
Now we can check the status again.
00:00
We can do a systemctl status, ssh,
00:00
and now we'll see that it's actually marked
00:00
disabled and it's also inactive and dead,
00:00
which means it stopped and it's disabled.
00:00
But you know what, ssh is important.
00:00
We want that so we can talk to
00:00
other Linux systems and they can talk to us.
00:00
Let's go ahead and re-enable it.
00:00
We're going to do a sudo systemctl and we'll change
00:00
this disable to an enable ssh.
00:00
Then we see that it creates those symlinks again.
00:00
Let's say that we want sshd to be
00:00
linked to sshd service and we want
00:00
that multiuser target to bring up ssh when we
00:00
boot into multiuser mode
00:00
when we're bringing up this Linux system.
00:00
Then we can also go ahead and start it.
00:00
Let's go ahead and do a sudo systemctl start ssh,
00:00
and now let's get a status again,
00:00
we don't need to run enable again, we already did that.
00:00
Sorry. Let's get the status again.
00:00
We see that it is active
00:00
and running and then it's enabled.
00:00
We just undid everything we did,
00:00
everything's back to normal. We're good to go.
00:00
Let's move on.
00:00
>> Another command that we can sometimes
00:00
>> run in systemctl is the daemon-reload command,
00:00
and that's used to restart
00:00
a service without disrupting users.
00:00
What it does is it rereads
00:00
application configuration files to pick up changes.
00:00
It doesn't actually restart the service.
00:00
This is commonly used with Apache
00:00
>> or HTTPD web services,
00:00
>> so the web page access isn't actually interrupted.
00:00
The way that we can run this command is with systemctl,
00:00
daemon or daemon, however, you want to pronounce this,
00:00
>> reload and we're going to use
00:00
>> sudo to do this so it doesn't
00:00
yell at us and request a password.
00:00
Now it's done.
00:00
>> In many times you might also need to
00:00
>> mask a service to ensure that
00:00
>> it absolutely doesn't run.
00:00
>> This is a service that you completely do
00:00
not want to run on the system,
00:00
you don't want it to start.
00:00
If we were to go ahead and do that,
00:00
let's pick on ssh again, just for fun.
00:00
We're going to use sudo systemctl
00:00
and we'll change this to say mask.
00:00
We're going to mask ssh. There we go.
00:00
What it does is it creates a symlink to /dev/null.
00:00
Basically, it just says, hey,
00:00
this all goes to the bit bucket.
00:00
Anytime you try and start this using systemd,
00:00
it's going to go to /dev/null
00:00
and nothing's going to happen.
00:00
Running systemctl mask changes that link.
00:00
>> It knows the bit bucket.
00:00
>> If we want to fix this,
00:00
we can unmask the same link and turn ssh back on.
00:00
You do sudo systemctl unmask ssh,
00:00
and now we see it removes that link to the ssh service.
00:00
If we run a systemctl status on ssh,
00:00
>> we see it's all fine again.
00:00
>> It's loaded, it's active,
00:00
it's enabled, and we're good to go.
00:00
But with that, we've reached the end of this lesson.
00:00
In this lesson, we covered how to use systemctl
00:00
to manage services with systemctl start,
00:00
restart, stop, reload, daemon-reload and mask.
00:00
We also covered how to configure
00:00
if services boot automatically
00:00
using systemctl enable and systemctl disable.
00:00
Thank you so much for being here and I look
00:00
forward to seeing you in the next lesson.
Up Next