Linux Change SSH Port (CentOS, Ubuntu, Debian, etc)

Changing the SSH port from the default 22 is a good idea for a few reasons, and it will cut out the majority of bots trying to connect and keep your logs cleaner.

Link to the video:

1.) Edit the /etc/ssh/sshd_config file with your preferred text editor.
nano /etc/ssh/sshd_config

2.) Find the line that has "#port 22" and un-comment the line, then change 22 to the port you wish to use.
#port 22
port 8340

Save the file. (With nano editor, press CTRL + X then Y to overwrite.)

3.) Restart the ssh service:
systemctl restart sshd or service sshd restart
systemctl restart ssh or service ssh restart

4.) If you use iptables or the standard Linux firewall, add a rule to allow traffic to the new SSH port. (If your firewall is empty, no need.)
ufw allow 8340
firewall-cmd --permanent --zone=public --add-port=8340/tcp
firewall-cmd --reload
iptables -A INPUT -i eth0 -p tcp --dport 8340 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 8340 -m state --state ESTABLISHED -j ACCEPT

That's it.

  • ssh, ssh port, change ssh port
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

KVM Virtualizor - how to use assigned IPv6 /112 subnet

To manage the IPv6 /112 subnet assigned to your KVM vps please use the following button to carve...

How to configure a secondary assigned IPv4 KVM

  If you run Debian or Ubuntu Edit /etc/network/interfaces auto eth0:0 iface eth0:0 inet...

Bandwidth Limit Reached

If you have reached the monthly bandwidth (the amount of traffic you're sending/receiving) limit,...

ScoHosting Terms of Service

Last update: November 11, 2019 Sco Hosting LTD Terms of Service Where the content states:...