Now what we're going to do now is dive a little bit
deeper into our service unit files.
When we look at our service units, they are very well documented.
If we need help on this,
we can go into our man page, the man page section 5, and systemd.service.
They've got some great examples, but they also describe
all of the settings that can be made.
We can also go through and view very easily without even
knowing the location of our service files.
We can use systemctl cat, and here we're looking at our sshd.service unit.
We might gain from that a little bit about the
ExecStart, so when we start our service,
we'll see that it's firing up our service, but with options. We can see that
those options then are being set from our /etc/default/ssh, and we can then go
through and put additional options that we might want.
Now, if we're having problems with our SSHD service,
we might decide that we want to go into debug mode, so we log more
information about the service and how it's running.
So if we add this to our default,
it's going to be passed through to our service unit
file. To be able to see this working,
we're going to dive out to our command line,
make sure we can read our sshd.service unit file, configure then the
options, and view the results after restarting our service.
So, hello, and welcome through to the command line, a command line where
we're going to dive straight in and make sure that we can locate the
help that we need on our systemd unit files.
So we can go through and do a man 5 for configuration files, and we can go
through and look for systemd.service for our service units.
When we go through and hit Enter on this,
we then obviously get our man page opening up, and we can look then for
anything that we don't perhaps understand from our unit files.
So I can go through, for example, and hit /, and then if
we go through and look at ExecStart, this is how a service is actually started.
We can see then the ExecStart equals. But as I go through,
I can hit the Next, so we can then process our way through, and
then we get examples of where it was used before, and then we get
the actual configuration option itself.
Once we've finished looking at our help,
obviously, we can then choose Q to jump out of it.
So if there is ever anything we don't understand in one of our unit
files, we'll go through and take a look at it.
We could also go through and say look at our systemd timers, and we want to
see what can be configured in a timer unit. We'll do a systemd.timer, and
then we've got the help on our timer units. Again,
I'm just going to drop out of this for the moment, so Q to jump out. Using
systemctl, we can go through and take a look at one of our service units. So
if I go through and look at SSHD and then Enter,
we can see then a service unit in practice. The unit itself is going
to be common across all of our unit files. The service is going to
be then relating through to our service unit. And we can see there
that we've got the ExecStart, the ExecReload, and as we go through,
maybe taking a look at our start,
we can see then that we start our SSH daemon with the SSHD command with
the option ‑D and then any other options that we've got.
Well, okay, that could be quite fun. But if we want to put our server,
let's say, into debug mode, we can get more information coming back.
But where are these SSHD options? Now I've got a couple of
choices. I could actually take that variable out and just
put the extra option that I want.
Alternatively, we could research it.
Just go through and take a look in your man page for the SSH daemon. But those
options themselves are going to come from, and let's go through and open it up,
sudo and vim, or any editor you want to use, /etc/default, and then ssh. And we
can see it's here where we are configuring those options. I'm going to go to the
end, and we just then put our quotes in; ‑d is an option to go into debug mode.
With debug mode, we'll be logging much more information, so if we are having
problems with our SSH Server, then we might be able to view what's going on.
So with that set, I go through then and Escape and save.
Now, of course, that's just the configuration file, but it's
going to be read when our service is restarted. So I can do a
sudo systemctl and restart sshd.
Now the reality is I shouldn't need to tell you that we've restarted our
service. So let's dive straight in and take a look at systemctl running as a
standard user and taking a look at the status of our SSHD service. So we can
see there that we are now loaded and running all of our normal stuff. We can
go through and take a look in our control group and we can see that the
option ‑d is included, so we know we have gone into debug mode. But then we
might be saying, well, normally we see a log file when we look at our status.
Well, no you don't; not when you do it as a standard user. We only
see the log files if we go in as our elevated user.
So if I go through then and do our sudo and !!,
you know those two exclamation marks, and repeat the last command and all of its
options and arguments, hit the big Enter key, and look at that, we get the same
top‑level information, but included towards the bottom we see some of that log
information. And included in that log information is our glorious debug
information, and that could be really useful for us for trying to diagnose
issues with our SSHD service.
So we're going to be able to see that extra information inside of our
logs. When we've finished with it, of course, we can return then to our
default file and remove that extra option.
But there you go, we've seen a little bit of how we can go
through and get help through the man pages to understand
what's in our service units.
We've then gone through and taken a look using the cat command to take a look
inside of a service unit, and then looked at how we can modify the startup of
one of our services to help us debug that service.
So let's return now to the slide so we might then summarize a little of what we've seen.