How To Enable And Configure SSH On Debian 12

For carrying out automated tasks which include accessing a Linux operating system like Debian 12 remotely the secure shell protocol is mostly used. It provides a safe and encrypted way to manage those remote systems, transfer files, and even access resources that might otherwise be inaccessible. On Debian 12 and other Linux distributions, the SSH comes pre-installed but it requires configuration steps to work properly.

How to Enable SSH on Debian 12

The secure shell protocol encrypts all communication between the client and server. This means any data exchanged, including usernames, passwords, and commands, is scrambled and unreadable to anyone snooping on the network. Usually, SSH comes as a client and server service in all Linux distributions which are pre-installed in Debian 12. So in case if your Debian 12 does not have SSH then install it using:

sudo apt install openssh-server

Installing SSH server on Debian 12

While installing the SSH server on Debian 12 its client application is installed automatically but if you only want to use its client service then use:

sudo apt install openssh-client

Installing SSH client on Debian 12

After the installation of SSH on Debian check its service status for client service by using the systemctl utility:

sudo systemctl status ssh

Checking SSH server status on Debian 12

If the service is disabled or inactive which is not the usual case then enable SSH on Debian 12 by running the following commands:

sudo systemctl enable ssh
sudo systemctl start ssh

Enabling SSH on Debian 12

To check the SSHD service which is used in the system which is to be accessed via SSH use the below command:

sudo systemctl status sshd

Checking SSH client status on Debian 12

Similarly to enable and start the SSHD daemon service run the below commands:

sudo systemctl enable sshd
sudo systemctl start sshd

Note: SSHD (Secure Shell Daemon) is the server-side program that runs on the host machine and listens for incoming SSH client requests. It’s comparable to a web server that serves HTTPS pages. On the other hand, SSH (Secure Shell) refers to both the protocol and the client program that uses this protocol to connect to the server.

Now if you are trying to access the root account of Debian 12 via SSH then you will get the permission error. In the below image, I am trying to access the root account of Debian 12 through Windows Powershell and getting the permission error:

SSH permission denied error for root login of Debian 12

To fix this issue you need to edit the SSH server configuration file:

sudo nano /etc/ssh/sshd_config

Here, allow the remote login for the root account by adding the following line:

PermitRootLogin yes

 

Allowing Debian 12 root Login via SSH

After saving the file I tried logging in to the root account of my Debian 12 through Windows PowerShell:

Accessing Debian 12 root account via Windows PowerShell

How to Set a Custom port on Debian 12 for SSH

The SSH by default uses port 22 to access the other systems which can make it an easy target for hackers. So for that, you can set custom ports for accessing other systems or transferring files via SSH. Apart from that you might get the error for connection refused as in the image below:

Port 22 connection refused error

In the case of a connection refused error open up the SSH server configuration file and see if the port is set other than 22 if yes then set it back to 22 and save the file. On the other hand, if you want to set a custom port then set any port number ranging from 1024 to 65535.

Adding a custom port for SSH on Debian 12

Next, allow the custom SSH port from the Debian 12 firewall:

sudo ufw allow 1046/tcp

Allowing Custom Port for SSH through firewall on Debian 12

Now restart the SSH service using the systemctl utility and then use the below syntax to access the system remotely:

ssh [user-name]@[system-ip-address] -p[custom-port]

Accessing Debian 12 from Arch Linux using custom SSH port

How To Access Arch Linux From Debian 12 via SSH 

Here I have accessed Arch Linux from Debian 12 using the SSH protocol by using the following syntax:

ssh [user-name]@[system-ip-address]

Accessing Arch Linux from Debian 12 using SSH

How To Access Debian 12 From Windows via SSH 

To access Debian 12 through Windows PowerShell first launch it with admin rights and then follow the below syntax:

ssh [user-name]@[system-ip-address]

Accessing Debian 12 from Windows PowerShell through SSH

Conclusion

To enable SSH on Debian 12 use the enable command along with the systemctl utility but before that verify the SSH server or client service status. If the service is not installed then use the Debian default app installer to install the SSH server. Further to make the connection more secure you can set a custom port by adding it in the SSH configuration file and then allowing it through the system firewall.

Index
Scroll to Top