How to change your SSH port on CentOS 7 [Firewall Setup Included] Print

  • 4

Changing the SSH Port on CentOS 7

1. Login to your server's SSH and make sure you are connected as the root user or have root user permissions.

2. Run the command below to make sure that all your package repositories are fully up to date:

sudo yum update

3. Run the command (you can replace "nano" with your preferred editor, for example, vi):

nano /etc/ssh/sshd_config

4. Locate the line that says:

#Port 22

5. Remove the hashtag before the line and replace "22" with your desired port number.

6. Leave the editor you were editing the file with.

7. Run the two commands below and replace 22 with the port number you chose above to ensure your firewall is not blocking connections to your desired port number.

sudo iptables -I INPUT -p tcp -m tcp --dport 22 -j ACCEPT 
sudo firewall-cmd --zone=public --add-port=22/tcp

Congratulations! You have now successfully changed your SSH port and allowed connections to it.

Was this answer helpful?

« Back

Powered by WHMCompleteSolution