In this video, you'll learn about system D sockets. System D sockets are used to listen
for incoming traffic on the socket. And when that occurs, start the matching service. As
you remember from the last lesson, a socket is typically a combination between an IP address
and a port. So you can define a socket to listen on port 22. And if any traffic is coming
in, you start the corresponding service, which obviously would typically be SSH. Like with
timers, the name of sockets must match the names of the services that they are starting.
And for an overview of them, you can use systemctl listunitfiles-dsockets. And when sockets are
used, it's a socket that is enabled and not the matching service. Let's go check this
out. So let's use systemctl listunitfiles-dsockets, which will list all the units of the type
socket. And as you can see, there's quite a few of them. Now, we have sshd.socket. And
I think this is a nice one for a demo. So currently, we have what? We have systemctl
status sshd.service, which means that sshd.service is running. It's enabled. And the preset is
enabled as well. Let's change it. I'm going to use systemctl disable minus minus now sshd.service.
Then I'm going to check systemctl cat sshd.socket. I want to know what's going on in this socket.
As you can see, it's a pretty simple configuration where it defines the socket. We have a listen
stream, which refers to a TCP port. The alternative is listen datagram, which refers to a UDP
port. And accept is yes. We'll make sure that it accepts incoming traffic. No further configuration
because sockets by default match on the basis of the first name. So I'm going to use systemctl
enable minus minus now sshd.socket. And then when I use systemctl status on sshd.socket,
then we can see that it is active and it is listening. It's listening on port 22.
And that is looking all right. And how about systemctl status sshd? There we can see that
sshd is loaded, but it is inactive and it is dead. So PSAUX
pipegrab ssh is not showing any ssh service at the moment. But when I'm going to use ssh
student at localhost, then what is going to happen? I am getting an answer anyway.
So I need to stay in this student ssh shell and open a sudo minus i root shell. And I'm using
systemctl status sshd. And I'm using systemctl status sshd, where we can see it's disabled
and it is inactive. And that is kind of funny, but it was started anyway. And PSAUX pipegrab
ssh is showing that the ssh process is currently in the list. And that proves how a socket is
working. Now I'm getting out of my socket connection. So I'm back in my ordinary root
shell. And PSAUX pipegrab ssh is showing me nothing. So if the traffic disappears on the
port that the socket is listening for, the corresponding service is stopped immediately.