Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
    • Security
Google Cloud Platform icon
Labs

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.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Apr 08, 2025
Duration
1h 0m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Configure `sshd` to use sockets.

    You will be using an active SSH connection to the server when you log in.

    1. Verify that the sshd.socket unit is not active:
        systemctl status sshd.socket
    

    The output should show that it is not active.

    1. We will need to set up an at job that will stop the sshd.service unit and start the sshd.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 the sshd.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.

    1. After the time has expired on the at job, verify that the sshd.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.

    1. Enable the socket for SSH and disable the service for SSH:
        sudo systemctl enable sshd.socket
        sudo systemctl disable sshd.service
    
  2. Challenge

    Set up TCP wrappers to only allow SSH.
    1. 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.

    1. Edit the /etc/hosts.allow file, and add the following:
        sshd2 sshd : ALL
    

    This will permit incoming SSH connections from any network.

    1. 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.

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

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.

Get started with Pluralsight