RHEL 6: Change OpenSSH Port To 1255 ( SELinux Config )

I’ve edited /etc/ssh/sshd_config to change the port number:

Port 1255

However, I’m getting an error as follows:

sshd[26792]: error: Bind to port 1255 on 192.168.1.100 failed: Permission denied

How do I change default OpenSSH port number from 22 to 1255 under RedHat Enterprise Linux server version 6 and SELinux?

By default SELinux only allows port number 22. To display current port contexts, enter:
# semanage port -l | grep ssh
Sample outputs:

ssh_port_t                     tcp      22

To add port 1255 to port contexts, enter:
# semanage port -a -t ssh_port_t -p tcp 1255
You can verify new settings, enter:
# semanage port -l | grep ssh
Sample outputs:

ssh_port_t                     tcp      1255,22

Finally, reload or restart the OpenSSH server, enter:
# /sbin/service sshd reload
Verify, sshd is listing on TCP port # 1255, enter:
# netstat -tulpn | grep 1255


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • Bhanu Prakash May 17, 2011 @ 2:43

    I think it’s throwing you permissions error but not the other way..

  • ALane Jun 7, 2011 @ 20:50

    If you’re changing the port to 1255, you should really remove the allow statement for port 22.
    semanage port -d -t ssh_port_t -p tcp 22

    • Sergani Jun 21, 2011 @ 11:59

      i’ll double that as well…

    • JMath Mar 31, 2012 @ 7:55

      Thanks, I was thinking exactly the same.

  • Jay Mar 20, 2012 @ 7:03

    I’m on CentOS 6.2, and I can’t remove Port 22 as per the instructions above — SElinux complains that port 22 is part of the ‘policy’ and can’t be removed. How do I fix this?

    • JMath Mar 31, 2012 @ 7:56

      Actually, I’ve spoke to soon and have encountered this as well.

  • skcho Nov 5, 2015 @ 3:05

    It’s a useful tip, still in 2015. Thanks!

  • sinuhet Feb 29, 2016 @ 15:43

    It’s a useful tip, still in 2016. Thanks!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum