×

SSH修改端口报错 error: Bind to port xxx on 0.0.0.0 failed: Permission denied.解决方法

hqy hqy 发表于2019-05-13 10:07:50 浏览5765 评论0

抢沙发发表评论

SSH修改端口报错 error: Bind to port xxx on 0.0.0.0 failed: Permission denied.解决方法


Linux修改ssh Port端口后,无法启动ssh访问。

具体修改  /etc/ssh/sshd_config 里的 Port 端口,然后查日志后出现:

error: Bind to port 77 on 0.0.0.0 failed: Permission denied.

最后发现是SELinux的问题,关闭SELinux。
关闭SELinux方法:https://www.landui.com/help/show-8381

1 永久方法 – 需要重启服务器

修改/etc/selinux/config文件中设置

SELINUX=disabled


2 临时方法 – 设置系统参数然后重启服务器。

使用命令setenforce 0

附:
setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式

然后重启ssh访问即可。



2

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

0

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.

7

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.

1

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



 您阅读本篇文章共花了: 

打赏

本文链接:https://kinber.cn/post/697.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

群贤毕至

访客