Loading

CentOS 7 SSH Port Change

 
- Login to your server and open the OpenSSH server configuration file, /etc/ssh/sshd_config for editing.

nano /etc/ssh/sshd_config

- Uncomment the line, # Port 22 and set it to a desired port. But as a safety measure, just in case things go south, configure sshd to listen on two ports, the default port and the desired port such that your config files have two lines like as shown below. Once you confirm that the new port works fine, remove the default port setting. 3456 is your preferred port

Port 22 Port 3456

- Ensure that no other service is using the new port.
Replace the ports accordingly.
If firewall is running, allow the new port on through it.

firewall-cmd --add-port=3456/tcp --permanent

firewall-cmd --reload

- Check Selinux

 getenforce

- If you get the "Enforcing" response when you run the command, it means SELinux is active. Therefore, follow the steps in this section.

sudo yum install -y policycoreutils-python
sudo yum install -y policycoreutils-python-utils
sudo semanage port -a -t ssh_port_t -p tcp 3456


- Restart sshd service

systemctl restart sshd

 


Was this article helpful?

mood_bad Dislike 4
mood Like 0
visibility Views: 16085