Table of Contents

    SSH (Secure Shell) is a cryptographic network protocol that provides secure remote access and control over a network. It allows users to log into and manage remote machines or servers securely. SSH plays a vital role in enabling secure remote access, file transfers, and encrypted communication for Debian users, enhancing their systems’ overall security and flexibility.

    Debian 12, the latest LTS of the Debian distribution, has been released, which offers more advanced security features and an improved user experience. You might be wondering how to configure or enable SSH on Debian 12. Well, it’s quite easy and takes no time. We have prepared this guide to teach you how SSH can be enabled and configured on Debian 12.

    This video file cannot be played.(Error Code: 224003)

    Prerequisites: Install SSH Server

    The purpose of the guide is to enable and configure SSH on Debian 12. Thus, before proceeding, you must ensure that the SSH is installed on your system. The command to install SSH on Debian 12 is as follows:

    $ sudo apt install openssh-server
    Debian 12 command to install openssh-server

    How to Configure and Enable SSH on Debian 12?

    Enabling and configuring SSH on Debian 12 is of utmost importance as it allows for secure remote access and administration of Debian servers. By enabling SSH, administrators gain the ability to manage their systems from any location remotely, eliminating the need for physical access. Let’s do it on Debian 12:

    Note: The SSH server is associated with the service named “ssh” on Debian 12. So, here the SSH keyword in commands will refer to the service that manages the SSH server on Debian 12.

    Step 1: Activate the SSH Server

    Right after the installation, the SSH service will be started automatically. However, if it is not. You can start the SSH service as follows:

    $ sudo systemctl start ssh
    Debian 12 command to start openssh-service

    Meanwhile, it is recommended to enable the SSH service as well to keep functioning the SSH after every restart:

    $ sudo systemctl enable ssh
    Debian 12 command to enable openssh-service


    To verify these, you need to check the status of the SSH service using the command:

    $ sudo systemctl status ssh
    Debian 12 command to check openssh-service status

    The output of the command shows that the SSH is also running in an active state and is enabled.

    Step 2: Add the Firewall Rules

    The SSH server listens to port 22, which depends on the approval of your system’s firewall. Here, the ufw utility will allow SSH over the firewall. To install the ufw on Debian 12, use the command:

    $ sudo apt install ufw
    Debian 12 command to install firewall server

    If the Port is Default (22):

    Now, use the allow option of the ufw utility to allow SSH on the firewall as follows:

    $ sudo ufw allow ssh
    Debian 12 command to allow ssh-server though the firewall (port 22 specific)

    If the Port is Other Than Default:

    What if the SSH is listening to a port other than 22? Then, you have to specify the port number in the command:

    $ sudo ufw allow <port-no>
    Debian 12 command to allow ssh-server though the firewall (if using a port other than port 22 )
    $ sudo ufw enable
    Debian 12 command to enable the Firewall service

    Debian 12 command to allow ssh-server though the firewall (if using a port other than port 22 )

    To verify it, check the status of the ufw utility in verbose mode as follows:

    $ sudo ufw status verbose
    Debian 12 command to view detailed firewall status report

    Test the SSH Server on Debian 12

    Once you have done the above-listed steps, you can make a new SSH connection. The command’s syntax to connect to the machine via SSH is:

    Syntax:

    $ ssh <username> @<Server-IPAddress>
    Generic command to remotely log-in to Debian 12 server

    Enter the username and the IP address of the server to whom you are establishing the connection. For example, we have created an SSH connection with a Linux server. You have to write “yes” to continue connecting and then insert the password of the server’s username that you entered in the command. Once the connection is established, you can see that the username and the hostname have been changed to the machine you are connected to.

    $ ssh adnan@192.168.1.11

    To break the connection, type exit and hit enter. The connection will be terminated instantly, as seen in our case:

    $ exit
    Commnd to exit your remote connection session.

    How to Disable SSH on Debian 12?

    What if you are now done with the SSH but still think some penetration can occur? Well, Linux is well-known for its security. However, this may happen on extremely exposed servers. You can avoid such cases by disabling the SSH and disallowing the SSH over the firewall.

    Stop the SSH Server’s service:

    $ sudo systemctl stop ssh
    Debian 12 command to stop the ssh-service on our server or host machine

    Deny the SSH Over Firewall

    $ sudo ufw deny ssh
    Debian 12 command to deny access to SSH connections in Firewall server

    That’s how you can configure the SSH on Debian 12.

    Wrap Up

    Being a Linux administrator, you must be aware of the importance of SSH, which is used to establish a remote connection. As you know, Debian 12 has just been released, and if you are an administrator working on Debian 12, then this guide is purely for you to configure/enable SSH on your Debian 12.

    The systemctl and the ufw utilities play a vital role in managing the SSH services on the system and on the firewall. We have listed all the steps with commands to configure and enable SSH on Debian 12. Moreover, the process to disable (just for security reasons) the SSH server is also demonstrated. Want more tips for system/network administrators? keep visiting Linux-Genie for daily updates.


    This article was first published here By Adnan Shabbir. Published on 03/07/2023.


    author’s Bio

    Adnan, a Software Engineer with an aim to learn and teach the community through words. The go-to expert for all things about Linux, Command Prompt, and Shell. He has honed his skills in crafting easy-to-understand documentation, tutorials, and articles on these powerful tools.

    More articles from this author:

    How to Configure Firewall on Debian 12?

    How to Install Cinnamon Desktop Environment (DE) on Debian 12

    Leave a Reply