Brief
Allow the following TCP port numbers on SSH server
22
2222
Premises
- The machine uses an Amazon Linux AMI distribution
- The SSH installation is based on an SELinux system
Details
By default, SSH uses TCP port 22
. Is it possible to allow the SSH server to accept inbound traffic from TCP port 2222
? If so... How?
I looked at the SSH's config file...
/etc/ssh/sshd_config
...
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
...
It tells that I should use semanage
to configure this section instead of overwriting the said file.
How to use semanage
to allow the SSH server to accept inbound traffic from 2 TCP port numbers mentioned above? Also both at the same time.
This comment means that you must do both.
You must specify all of the desired
Port
s insshd_config
, and you must also runsemanage
as shown if you wish to add any ports other than 22.For example:
Then you would run
semanage
:After doing both of these, it is safe to restart OpenSSH.
It is as simple as adding (additional to the default implied 22)
Port
directives in yoursshd_config
fileWith regards to the SELinux related command, that is usually only relevant on Red Hat related distributions such as RHEL, Fedora and CentOS
And
Will add 2222 as a valid port for ssh to the ssh policy on the server running sshd