How to change SSH port on Centos 7.x?

SSH or secure shell is a network protocol. We use it to connect and access remote servers. We can change the default SSH port to enforce the security against the brute force attacks on your servers. 

Please refer to the following steps to change the default SSH port on CentOS.

  1. Login to your CentOS server using root or sudo user.

  2. Open the file sshd_config at the path /etc/ssh using the below command in your favorite editor. 

  3. Uncomment the line mentioned port 22 and change it to your required port. Here we have changed it to port 8756.

  4. Save and exit from the sshd_config file. 

  5. If you have installed the firewall on your server, please ensure that you add the new RDP port. Else, it will not allow connecting your system using ssh.

    Allow SSH port on Firewalld

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

    Allow SSH port on Iptables

    iptables -A INPUT -p tcp -m tcp --dport 8756 -j ACCEPT
    systemctl restart iptables
  6. Run the below command to restart the ssh service. 

    systemctl restart sshd

Related Articles

How to install OPcache in cPanel/WHM?

OPcache is a PHP extension and it helps to improve the performance of your php Website. OPcache...

How to change the timezone on Ubuntu 18.04 Server?

You can perform the below steps using root or sudo users. Check your current timezone by...

How to setup VSFTPD on CentOS 7.x?

VSFTPD is an FTP server for Unix/Linux systems. It is a default FTP server on CentOS, RHEL Linux...

How to Configure VSFTPD with SSL/TLS encrypted connection?

Before you proceed with these steps, ensure that you have installed the VSFTP on your Linux...

How to Install phpMyAdmin on CentOS 7?

phpMyAdmin is a web-based GUI tool to manage your MySQL and MariaDB Databases. It is an...

  • 0 Users Found This Useful

Was this answer helpful?