CentOS 6.3. SSH. Bind to port xxx on 0.0.0.0 failed: Permission denied

Viewed 19499

CentOS 6.3 Minimal Configuration. Installed SSH Server, port 22. All works correctly. I change port 22 on 777 and restart sshd and see in logs:

Jul 26 01:01:07 myserver sshd[1590]: error: Bind to port 777 on 0.0.0.0 failed: Permission denied.
Jul 26 01:01:07 myserver sshd[1590]: error: Bind to port 777 on :: failed: Permission denied.
Jul 26 01:01:07 myserver sshd[1590]: fatal: Cannot bind any address.

/etc/sysconfig/iptables contains:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 777 -j ACCEPT

netstat -tulpn | grep :22 and netstat -tulpn | grep :777 return nothing

5 Answers

you can disable selinux with command sudo setenforce 0.

sudo setenforce 0

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

firewall-cmd --reload

The problem is informing SELinux, but I think there are two cases:

  1. the port is not already allocated for a built-in service, in such case, this may work:

    sudo semanage port -a -t ssh_port_t -p tcp 22777
    
  2. the port is overwriting some existing service (don't ask me why); in this case this slightly different syntax is necessary:

    sudo semanage port --modify -t ssh_port_t -p tcp 777
    

Of course, such ports should be then made available by updating the firewall:

sudo firewall-cmd --add-port=22777/tcp --permanent

or

sudo firewall-cmd --add-port=777/tcp --permanent

and then:

sudo firewal-cmd --reload
Related