To change SSH port of the Linux server, you need to login into the server via SSH and modify SSH config file.

# vim /etc/ssh/sshd_config

In the first section, find #Port 22.

Change the Port 22 to the port you want to set for SSH.

After modifying the file, save the changes.

Restart sshd.service.

# systemctl restart sshd

Verify the changes

# ss tlupn | grep sshd


tcp    LISTEN     0      128       *:$port                 *:*                   users:(("sshd",pid=1135,fd=3))
tcp    LISTEN     0      128      :::$port                :::*                   users:(("sshd",pid=1135,fd=4))

Add the port into the firewall

# firewall-cmd --zone=public --add-port=$port/tcp --permanent

Reload the firewall

# firewall-cmd --reload

Everything is set. Now you can reboot the server and login into the server via SSH using the new port.

# ssh -p $port [user]@[IP address]

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution