1
00:00:00,000 --> 00:00:11,720
In this video, you'll learn about system D sockets. System D sockets are used to listen

2
00:00:11,720 --> 00:00:17,600
for incoming traffic on the socket. And when that occurs, start the matching service. As

3
00:00:17,600 --> 00:00:22,719
you remember from the last lesson, a socket is typically a combination between an IP address

4
00:00:22,719 --> 00:00:28,440
and a port. So you can define a socket to listen on port 22. And if any traffic is coming

5
00:00:28,440 --> 00:00:35,080
in, you start the corresponding service, which obviously would typically be SSH. Like with

6
00:00:35,080 --> 00:00:40,680
timers, the name of sockets must match the names of the services that they are starting.

7
00:00:40,680 --> 00:00:47,639
And for an overview of them, you can use systemctl listunitfiles-tsockets. And when sockets are

8
00:00:47,639 --> 00:00:53,439
used, it's a socket that is enabled and not the matching service. Let's go check this

9
00:00:53,439 --> 00:01:02,439
out. So let's use systemctl listunitfiles-tsockets, which will list all the units of the type

10
00:01:02,439 --> 00:01:09,360
socket. And as you can see, there's quite a few of them. Now, we have sshd.socket. And

11
00:01:09,360 --> 00:01:16,480
I think this is a nice one for a demo. So currently, we have what? We have systemctl

12
00:01:16,480 --> 00:01:24,599
status sshd.service, which means that sshd.service is running. It's enabled, and the preset is

13
00:01:24,599 --> 00:01:34,720
enabled as well. Let's change it. I'm going to use systemctl disable minus minus now sshd.service.

14
00:01:34,720 --> 00:01:42,820
Then I'm going to check systemctl cat sshd.socket. I want to know what's going on in this socket.

15
00:01:42,820 --> 00:01:48,980
As you can see, it's a pretty simple configuration where it defines the socket. We have a listen

16
00:01:48,980 --> 00:01:55,699
stream, which refers to a TCP port. The alternative is listen datagram, which refers to a UDP

17
00:01:55,699 --> 00:02:02,580
port. And accept is yes. We'll make sure that it accepts incoming traffic. No further configuration

18
00:02:02,580 --> 00:02:09,860
because sockets by default match on the basis of the first name. So I'm going to use systemctl

19
00:02:09,860 --> 00:02:22,339
enable minus minus now sshd.socket. And then when I use systemctl status on sshd.socket,

20
00:02:22,339 --> 00:02:27,220
then we can see that it is active, and it is listening. It's listening on port 22.

21
00:02:27,940 --> 00:02:35,860
And that is looking all right. And how about systemctl status sshd? There we can see that

22
00:02:35,860 --> 00:02:42,100
sshd is loaded, but it is inactive, and it is dead. So psaux,

23
00:02:44,100 --> 00:02:51,539
pipegrab ssh is not showing any ssh service at the moment. But when I'm going to use ssh

24
00:02:51,539 --> 00:02:57,619
student at localhost, then what is going to happen? I am getting an answer anyway.

25
00:02:58,580 --> 00:03:05,940
So I need to stay in this student ssh shell and open a sudo minus i root shell. And I'm using

26
00:03:05,940 --> 00:03:16,020
systemctl status sshd. And I'm using systemctl status sshd, where we can see it's disabled,

27
00:03:16,020 --> 00:03:21,220
and it is inactive. And that is kind of funny, but it was started anyway.

28
00:03:22,179 --> 00:03:31,059
And psaux, pipegrab ssh is showing that the ssh process is currently in the list. And that proves

29
00:03:31,059 --> 00:03:36,899
how a socket is working. Now I'm getting out of my socket connection. So I'm back in my ordinary

30
00:03:36,899 --> 00:03:44,899
root shell, and psaux, pipegrab ssh is showing me nothing. So if the traffic disappears on the port

31
00:03:44,899 --> 00:03:50,100
that the socket is listening for, the corresponding service is stopped immediately.

