How to Enable SSH on Debian 12

How to Enable SSH on Debian 12

SSH (Secure Shell) protocol allows Debian users to enable encrypted connections and tunneling between two devices using the unsecured Internet. It is an essential tool in operating systems including Debian for transferring files from one device to another and remotely accessing the system’s terminal. The conversations are like a secret tunnel that keeps the connection safe and private.

The SSH runs at TCP/IP port 22 and uses a client-server architecture where the client initiates a connection and requests a secure connection to the remote device. It makes the connection between remote servers and devices more secure.

Quick Outline


How to Install SSH on Debian 12

On some Linux distributions, SSH is not installed by default. You can check whether the SSH service is installed on your system by executing the following command:

ssh localhost

If the output is “Connection refused”, it is confirmed that the SSH server is not installed on your system.

Update the system before installing the SSH server on Debian:

sudo apt update && sudo apt upgrade -y

Once your system is up to date, run the following command on the terminal to install SSH on Debian:

sudo apt install openssh-server -y

You can also check the version of SSH on Debian to confirm its installation:

ssh -V


How to Start SSH Service on Debian 12

The SSH service automatically starts, once the process of installation completes. To verify SSH server is installed and running on your device, run the following systemctl command:

systemctl status ssh

In case, the SSH server is not running on your system, run this command to enable it:

sudo systemctl start ssh

The SSH server is successfully installed and running on your Debian system. You can also enable the SSH service on Debian through the following command, so it automatically starts wherever you boot the device:

sudo systemctl enable ssh

How to Configure Firewall Status of SSH on Debian 12

The SSH server runs on port 22 by default and requires the approval of a Firewall on your system to establish a secure connection. To allow SSH over Firewall with UFW, execute the following command:

sudo ufw allow ssh

Note: Ensure UFW is installed on your system, if it’s not, you can use the below-given command to install UFW on Debian 12:

sudo apt install ufw -y

If the SSH server is running over another port instead of 22 then specify the port using the following fundamental syntax:

sudo ufw allow <port-no>

Execute the verbose command to verify the current status of SSH over the Firewall:

sudo ufw status verbose


How to Configure SSH on Debian 12

To improve the security of the device while using SSH, edit the SSH configuration file. To do this, first, open the SSH file on Debian using the below command:

sudo nano /etc/ssh/sshd_config

The following are the various ways to improve the security of SSH on Debian 12:


1: Change Default Port of SSH

You can change the default port 22 of SSH in Debian 12 for improving your device security. To do so, open the configuration file and look for line #Port 22. Next, uncomment the line and replace the 22 with the desired port number:


2: Limit the Number of Users

By default, the maximum session allowed by SSH is 10. If you want to limit the number of users to access your Debian 12 using SSH, then in the same configuration file, uncomment the line MaxSessions and change the number 10 with the number of your choice:


3: Enable/Disable Login as a Root

Root login via SSH in Debian is permitted by default. However, you can change the settings if you want to remotely access your Debian system. Generally, it is not recommended to enable root login for security purposes. Instead, you can use the sudo prefix while executing the commands to run them as administrative. If you still want to do so, then in the file, find the PermitRootLogin prohibit-password. Uncomment the line and replace the prohibit-password with yes to enable or No to disable:


4: Allow/Deny Users

You can allow or deny specific users to SSH into your Debian system. Add the following lines at the end of the file and replace the user_name with the name of the user you want to allow or block:

AllowUsers <user_name>

To block users to SSH into Debian, add:

DenyUsers <user_name>

Once you are done editing the configuration file of SSH, press Ctrl + X and hit Y to save the file. To apply the changes restart the service using the following command:

sudo systemctl restart ssh

How to Connect With Remote Device Using SSH on Debian 12

The following are the prerequisites to connect to a remote device using SSH on Debian 12:

  • The remote computer is turned on and has a secure SSH enabled.
  • Obtain IP address and name of the host machine.
  • Ensure you have permission to access the other device.
  • Verify the firewall settings on both the host and remote servers.

To set a secure remote connection with another device, the following is the basic syntax:

ssh username@host_ip_address

Here, the username is the server user name and host_ip_address is the IP address of the server you want to establish a connection with.

To get the IP address of your system, execute the following command:

hostname -I

The following is the example command to establish a connection to the Debian system of username linuxways:

ssh linuxways@

A message will appear on your screen asking you to confirm, type yes and enter the password of the user name of the server to continue:

Once done you will be able to log in to your debian system through SSH. To break or exit the connection, type the following command in the terminal:



How to Disable SSH on Debian 12

If you ever want to stop the SSH service on Debian 12, run the below-written command:

sudo systemctl stop ssh

Moreover, you can also disable the SSH service from starting up automatically when you restart your system through the following command:

sudo systemctl disable ssh


How to Uninstall SSH on Debian 12

Just run the following command to completely remove the SSH service from your Debian system:

sudo apt remove openssh-server -y



SSH is a service that provides a secure and safe tunnel to connect with remote servers over the Internet. To connect with a remote host on Debian 12, you must have the necessary permissions, the IP address of the system, and its username. You should also require installing and enabling the SSH service in order to use it on your Debian system. The above-given sections of this article will help you in installing, enabling and making necessary changes to the configuration file. It will help you access the system remotely in a secure fashion and prevent unwanted access to your system.


Similar Posts