How-to change SSH port number in RHEL-7

SSH is a networking protocol used for accessing the CLI(shell) remotely with applications.  In RHEL7, ssh will be by default running as a daemon service called sshd in port 22,

systemctl status sshd.service

It is installed by the package called openssh, which will act as both as server and client, if it is not installed, install  it with the command
yum install openssh*


Server and Client SSH

EX: To access



which will open the shell of using the default port 22 after entering the password


Two ways you can login to remote host with ssh

  1. with password – less secure (because it uses passwords for authentication)
  2. without password – more secure (because it uses keys for authentication)

In this blog I want to show you how to secure the ports of SSH

We know that ssh server will by default runs in port number 22,

To Make SSH Server runs on Port number 222 when SELinux and Firewalld is enabled, you have to edit the file /etc/ssh/sshd_config in server

Port 222 #Line no 17

Allow firewall for this port
firewall-cmd --add-port=222/tcp --permenent
firewall-cmd --reload

Manage Port for SELinux
semanage port -a -t ssh_port_t -p tcp 222
semanage port -l | grep ssh #to verify

Restart the Service
systemctl restart sshd.service

Acess the server from client machine with the new port which you only knows
ssh -p 222


Leave a Reply