Systemd Unit Files

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
CEU/CPE
21
Video Transcription
00:00
>> Hello Cybrarians. Welcome back to
00:00
the Linux plus course here at Cybrary.
00:00
I'm your instructor Ralph Gillis.
00:00
In today's lesson, we're going to be talking
00:00
about these things called systemd unit files.
00:00
Upon completion of this lesson,
00:00
you are going to be able to understand the purpose of
00:00
unit files and how systemd uses them.
00:00
We're going to talk about the different
00:00
types of unit files.
00:00
We're going to talk about automount
00:00
and service unit files.
00:00
Then finally at the end of the lesson,
00:00
we're going to cover the directories that
00:00
hold the systemd unit files.
00:00
Unit files are the basic objects or
00:00
building blocks that systemd knows how to operate.
00:00
Everything in Linux is a file.
00:00
Are you sick of hearing this yet?
00:00
Everything in Linux is a file
00:00
and systemd uses unit files.
00:00
We can list all unit files with
00:00
the command systemctl list
00:00
units and then we can narrow it
00:00
down to unit file type by saying
00:00
systemctl list-units --type=service.
00:00
I do this a lot, if I'm looking at a system and going,
00:00
do we actually have the service?
00:00
Does the system know about it? Is it running?
00:00
We start out by going systemctl
00:00
list-units --type=service,
00:00
and figure out if the system knows about
00:00
the service that we want to run or ensure is running.
00:00
Now there are actually 12 types of unit files.
00:00
I'm not going to go through all of them here.
00:00
In all honesty,
00:00
the Linux plus course doesn't care if
00:00
you know about all types of unit files,
00:00
but it is worth mentioning because if you do
00:00
get into the nitty-gritty of Linux at any point,
00:00
you'll need to know about all the different things
00:00
that run as a unit file.
00:00
But for this lesson, we're going
00:00
to go forward and talk about
00:00
automount and service unit file types.
00:00
In the next lesson we're going to cover
00:00
target unit file types.
00:00
Let's talk a little bit about automount.
00:00
Automounting takes place when a process is trying to
00:00
access a resource and it's actually is
00:00
done on the fly hence, automount.
00:00
The resource is mounted when used by the process and
00:00
then gets unmounted when the process
00:00
isn't using it anymore.
00:00
Previously, this was handled in Linux
00:00
by something called autofs
00:00
but systemd is replacing
00:00
autofs with these automount files.
00:00
We can see an example of one of
00:00
these automount files on the right-hand side.
00:00
Now the service unit file is
00:00
the most commonly used type of
00:00
unit file and it's used to configure
00:00
environment settings for a service.
00:00
It tells you when a service is started,
00:00
how a service is started and
00:00
any targets that want the service,
00:00
which we're going to cover in the next lesson.
00:00
But we can see the ssh service file here on
00:00
the right-hand side and we can just see really
00:00
that it has wanted by multi-user target.
00:00
We see the description,
00:00
the location of the documentation,
00:00
and a bunch of other really good information
00:00
here in this file.
00:00
In fact, one of the things that we see is
00:00
the ssh service file has an EnvironmentalFile line.
00:00
These are generally used to configure
00:00
a specific environmental settings for the service.
00:00
The example here is that ssh needs
00:00
a random number generator to
00:00
>> pretty much use encryption.
00:00
>> We have SSH_ USE_ STRONG_RNG,
00:00
which stands for random number generator on the system.
00:00
Now, unit files are located in a few places in Linux.
00:00
Generally what it is is that there's an order of
00:00
precedence depending upon where they're located.
00:00
The first place that you may find
00:00
these unit files will be in /usr/lib/systemd/system,
00:00
and these are the unit files that get
00:00
installed with the Linux operating system.
00:00
These are the basic things that
00:00
come when you install the OS on the system.
00:00
Now the other things that you're going to find
00:00
some times are going to be in /run/systemd/system.
00:00
These are unit files that get created at runtime,
00:00
which means that as a service boots,
00:00
it's actually using or creating these files at runtime.
00:00
Then finally the /etc/systemd/system file
00:00
or folder directory
00:00
contains custom or modified unit files
00:00
that are created by you, the system administrator.
00:00
The unit files in this location have
00:00
the highest precedence and that's because
00:00
if you're going in as system administrator saying,
00:00
I want this thing to happen.
00:00
I want this unit to work a certain way.
00:00
You want that to take priority
00:00
>> over all the other places.
00:00
>> Definitely remember these locations and
00:00
definitely memorize this information for the exam
00:00
because I guarantee they're
00:00
going to ask you some information about
00:00
either the directory locations or
00:00
the precedence order of how
00:00
those systemd unit files are read.
00:00
But with that, we've reached the end of this lesson.
00:00
In this lesson we covered;
00:00
the purpose of unit files,
00:00
the different types of unit files,
00:00
we talked about automount and
00:00
service specifically in this lesson,
00:00
we covered environmental variables
00:00
that you'll find in unit files
00:00
and then we also talked about
00:00
the directory locations for unit files.
Up Next