- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
- Security

Host Security with TCP Wrappers and Systemd Sockets
A Linux system administrator is responsible for keeping their servers secure. There are a multitude of tools and software packages available to keep a networked Linux system safe from malicious intruders. In this hands-on lab, we will learn how to move away from always-on services to those that use systemd socket units. Socket units only provide access to a network service when an incoming connection requests it. To further enhance the security of the service, we will apply TCP wrappers to allow incoming connections to a specified service.

Lab Info
Table of Contents
-
Challenge
Configure `sshd` to use sockets.
You will be using an active SSH connection to the server when you log in.
- Verify that the
sshd.socket
unit is not active:
systemctl status sshd.socket
The output should show that it is not active.
- We will need to set up an
at
job that will stop thesshd.service
unit and start thesshd.socket
for us. Run the following commands in this sequence:
sudo at now + 3 minutes at> systemctl stop sshd.service at> systemctl start sshd.socket at> <EOT>
The
is from the key combination Ctrl+D. After three minutes, the sshd.service
will stop, and thesshd.socket
unit will take over for your connection, so your remote shell should not disconnect. If it does, SSH back into the learning activity again.- After the time has expired on the
at
job, verify that thesshd.socket
unit is active and running:
systemctl status sshd.socket
Now any new secure shell connections that come into the system will utilize an on-demand socket. This way, the server does not have to keep a running secure shell running.
- Enable the socket for SSH and disable the service for SSH:
sudo systemctl enable sshd.socket sudo systemctl disable sshd.service
- Verify that the
-
Challenge
Set up TCP wrappers to only allow SSH.
- First, verify that the
sshd
server has been compiled to use TCP wrappers:
ldd /usr/sbin/sshd | grep libwrap
You should see that the
sshd
binary is capable of being used with TCP wrappers.- Edit the
/etc/hosts.allow
file, and add the following:
sshd2 sshd : ALL
This will permit incoming SSH connections from any network.
- Now set up a default deny rule for TCP wrappers to deny any other incoming connections. Edit the
/etc/hosts.deny
file and add the following:
ALL : ALL
Exit out of the SSH session and attempt to reconnect. Provided that the commands have been entered as described, you will be granted access back into the system.
- First, verify that the
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.