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
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
After the installation of SSH on Debian check its service status for client service by using the systemctl utility:
sudo systemctl status ssh
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
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
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:
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
After saving the file I tried logging in to the root account of my Debian 12 through 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:
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.
Next, allow the custom SSH port from the Debian 12 firewall:
sudo ufw allow 1046/tcp
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]
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]
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]
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.