• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

“error: Bind to port 2222 on 0.0.0.0 failed: Permission denied” – error while starting sshd service on CentOS/RHEL

by admin

The Problem

On CentOS/RHEL, the OpenSSH SSH Daemon (sshd) utilizes port 22 for incoming connection requests from remote OpenSSH SSH (ssh) and Secure File Transfer (sftp) clients. In some cases, however, System Administrators prefer to utilize separate ports to service ssh and sftp activity. In One such case, system administrator is facing below error while starting sshd service

sshd[13798]: error: Bind to port 2222 on 0.0.0.0 failed: Permission denied.
sshd[13798]: error: Bind to port 2222 on :: failed: Permission denied.
sshd[13798]: Server listening on 0.0.0.0 port 22.
sshd[13798]: Server listening on :: port 22

The Solution

sshd was recently re-configured to use additional and/or non-default network ports. By default, sshd is configured to utilize network port 22. For example:

# grep ssh /etc/services
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
ssh 22/sctp # SSH

SELinux, also enabled by default, similarly expects and enforces sshd to utilize network port 22 exclusively. If re-configuring sshd to utilize additional and/or a non-default port, SELinux prevents the use of the port resulting in the observed Permission denied error.

1. Identify current SELinux permitted sshd listen ports.

# semanage port -l | grep ssh
ssh_port_t tcp 22

2. Configure SELinux to allow sshd to utilize additional port 2222.

# semanage port -a -t ssh_port_t -p tcp 2222

3. Verify new SELinux permitted sshd listen ports.

# semanage port -l | grep ssh
ssh_port_t tcp 2222,22

4. Restart the sshd service for the changes to take effect.

For CentOS/RHEL 7/8:

# systemctl restart sshd
# systemctl status sshd

For CentOS/RHEL 5/6:

# service sshd restart
# service sshd status

Filed Under: CentOS/RHEL, CentOS/RHEL 5, CentOS/RHEL 6, CentOS/RHEL 7, CentOS/RHEL 8, Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to disable BASH shell history
  2. How to set ulimit values for a systemd service
  3. How to Disable or set SELinux to Permissive mode
  4. pw-play Command Examples in Linux
  5. How to Check vendor of installed RPM packages in Linux
  6. The Squid Service in Failed State with Error: “Failed to make swap directory /var/spool/squid/00: (13) Permission denied”
  7. chgrp: command not found
  8. lrunzip Command Examples in Linux
  9. quotaon command examples in Linux
  10. How to Clone Linux disk partition over network using dd

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright