Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
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
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 1h 0m
Published
Clock icon Nov 12, 2018

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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans