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

17,711

Solution 1

Port 777 is dedicated for Multiling HTTP and even though not in use you can't bind to it. If you try for example to bind to port 8777 it will work just fine.

Solution 2

Centos uses SELinux by default and I don't think Ubuntu does (or least I've not seen it). Have a look for SElinux permission errors in your logs too.

Solution 3

SELinux does not allow sshd to be run on another port on a default install of CentOS 6.3. Follow -> https://blog.tinned-software.net/change-ssh-port-in-centos-with-selinux/ :

  • dig a hole into your firewall (you already did that)
  • add a rule for SELinux to allow sshd to be run on port 777: sudo semanage port -a -t ssh_port_t -p tcp 777

Solution 4

you can disable selinux with command sudo setenforce 0.

sudo setenforce 0

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

firewall-cmd --reload

Share:
17,711
indapublic
Author by

indapublic

Updated on June 11, 2022

Comments

  • indapublic
    indapublic almost 2 years

    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