Linux下sshd启动失败问题解决

A服务器sshd服务重启不了,总是stop failed。start正确。A服务器上能连接上其他ssh服务器,但是其他机器不能连接到A的ssh服务。 

[root@localhost ~]# /etc/init.d/sshd restart

[root@localhost ~]# cat /proc/version
Linux version 2.6.18-164.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Thu Sep 3 03:28:30 EDT 2009

检查日志(/var/log/secure 文件)发现如下错误提示:

Nov 14 12:10:41 localhost sshd[31842]: fatal: Cannot bind any address.
Nov 14 12:11:18 localhost sshd[31996]: fatal: Cannot bind any address.
Nov 14 12:11:20 localhost sshd[32016]: fatal: Cannot bind any address.
Nov 14 12:15:52 localhost sshd[32320]: fatal: Cannot bind any address.
Nov 14 12:17:18 localhost sshd[32527]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.
Nov 14 12:17:18 localhost sshd[32527]: fatal: Cannot bind any address.
Nov 14 12:17:19 localhost sshd[32538]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.
Nov 14 12:17:19 localhost sshd[32538]: fatal: Cannot bind any address.

提示显示端口22被占用,绑定失败。

在网上可以找到类似的案例,一般的解释是ipv4与ipv6启动冲突。
修改后的/etc/ssh/sshd_config 文件配置如下:

[root@localhost ~]# cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
Port 38475
#Protocol 2,1
Protocol 2
#AddressFamily any
ListenAddress 0.0.0.0
#ListenAddress ::

重启sshd服务正常。

 

大部分服务器报这个纯粹配置问题,关闭IPV6的监听就可以。但不能连接远程服务器应该应用程序损坏有关系

#cat /etc/ssh/sshd_config
……
#Port 22
#Protocol 2,1
#ListenAddress 0.0.0.0
#ListenAddress ::
……
#service sshd restart
#cat /var/log/secure
……
Dec 3 11:10:19 localhost sshd[25953]: Server listening on :: port 22.
Dec 3 11:10:19 localhost sshd[25953]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.
……

修改配置后:

#cat /etc/ssh/sshd_config
……
Port 22
#Protocol 2,1
ListenAddress 0.0.0.0
#ListenAddress ::
……

#service sshd restart
#cat /var/log/secure
……
Dec 3 11:10:43 localhost sshd[25968]: Server listening on 0.0.0.0 port 22.
……

修改了个ssh服务的端口,关闭ipv6后,重启sshd正常。

About 智足者富

http://chenpeng.info

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>