Skip to main content

Debian SSH Port and Hostname

Battambang, Cambodia

Changing the SSH Port

Adjusting Firewall

sudo firewall-cmd --permanent --zone=public --add-port=34567/tcp
sudo firewall-cmd --reload

Configuring SSH

Open the SSH configuration file /etc/ssh/sshd_config with your text editor:

sudo vim /etc/ssh/sshd_config

Search for the line starting with Port 22. In most cases, this line starts with a # character. Remove the hash and enter the new SSH port number 23456. Once done, save the file and restart the SSH service to apply the changes:

sudo systemctl restart sshd

To verify that SSH daemon is listening on the new port 23456, type:

netstat -ntlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:23456 0.0.0.0:* LISTEN 12271/sshd

Now test that you are able to connect to via the new port BEFORE exiting your current session :) :

ssh -p 23456 username@remote_host_or_ip

Change the Hostname

To set the hostname to myserver, run:

hostnamectl set-hostname myserver

Edit the file /etc/hosts and update entries still using the old hostname:

nano /etc/hosts

Verify it by running:

hostnamectl

Static hostname: myserver
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-10-amd64
Architecture: x86-64