SSH无法连接服务器

来源:互联网 发布:linux 的办公软件 编辑:程序博客网 时间:2024/05/03 03:23

服务器版本如下:

@kelWEB4:/etc# lsb_release -aLSB Version::core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarchDistributor ID:RedHatEnterpriseServerDescription:Red Hat Enterprise Linux Server release 6.2 (Santiago)Release:6.2Codename:Santiago

服务器内核如下:

@kelWEB4:/etc# uname -aLinux kelWEB4 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 x86_64 x86_64 GNU/Linux

1 ssh无法连接服务器

1.1查看日志message

vi /var/log/messages 在日志里可以看到内容如下:

May 18 03:40:20 kelWEB4 sshd[18527]: error: This private key will be ignored.May 18 03:40:20 kelWEB4 sshd[18527]: error: bad permissions: ignore key: /etc/ssh/ssh_host_rsa_keyMay 18 03:40:20 kelWEB4 sshd[18527]: error: Could not load host key: /etc/ssh/ssh_host_rsa_keyMay 18 03:40:20 kelWEB4 sshd[18527]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@May 18 03:40:20 kelWEB4 sshd[18527]: error: @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @May 18 03:40:20 kelWEB4 sshd[18527]: error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@May 18 03:40:20 kelWEB4 sshd[18527]: error: Permissions 0644 for '/etc/ssh/ssh_host_dsa_key' are too open.May 18 03:40:20 kelWEB4 sshd[18527]: error: It is recommended that your private key files are NOT accessible by others

1.2解决方法

从日志中可以看到是相关的权限有问题,从而查看ssh的配置文件的相关权限:

正确的权限设置如下:

       Ssh的配置文件目录在/etc/ssh/目录下

@kelWEB4:/etc/ssh# lltotal 164-rw-------. 1 root root 125811 Sep  7  2011 moduli-rw-r--r--. 1 root root   2047 Sep  7  2011 ssh_config-rw-------  1 root root   3890 Dec  7  2012 sshd_config-rw-r--r--  1 root root   3871 Dec  7  2012 sshd_config.20121207-rw-------. 1 root root    672 Jul 21  2012 ssh_host_dsa_key-rw-r--r--. 1 root root    590 Jul 21  2012 ssh_host_dsa_key.pub-rw-------. 1 root root    963 Jul 21  2012 ssh_host_key-rw-r--r--. 1 root root    627 Jul 21  2012 ssh_host_key.pub-rw-------. 1 root root   1675 Jul 21  2012 ssh_host_rsa_key-rw-r--r--. 1 root root    382 Jul 21  2012 ssh_host_rsa_key.pub@kelWEB4:/etc/ssh# ll -d /etc/sshdrwxr-xr-x. 2 root root 4096 Dec  7  2012 /etc/ssh

大部分的权限为0600,如果此处权限设置错误,那么会导致ssh无法连接到服务器中

2 用户不能使用su来进行切换用户

2.1 查看日志secure

日志存放的为/var/log/secure,查看内容报错如下:

May 12 17:28:47 kelWEB4 su: PAM (su-l) illegal module type: minlen=8May 12 17:28:47 kelWEB4 su: PAM pam_parse: expecting return value; [...minclass=2]May 12 17:28:47 kelWEB4 su: PAM (su-l) no module name suppliedMay 12 17:28:47 kelWEB4 su: PAM (su-l) illegal module type: minlen=8May 12 17:28:47 kelWEB4 su: PAM pam_parse: expecting return value; [...minclass=2]May 12 17:28:47 kelWEB4 su: PAM (su-l) no module name suppliedMay 12 17:28:47 kelWEB4 su: PAM (su-l) illegal module type: minlen=8May 12 17:28:47 kelWEB4 su: PAM pam_parse: expecting return value; [...minclass=2]May 12 17:28:47 kelWEB4 su: PAM (su-l) no module name suppliedMay 12 17:28:47 kelWEB4 su: PAM (su-l) illegal module type: minlen=8May 12 17:28:47 kelWEB4 su: PAM pam_parse: expecting return value; [...minclass=2]May 12 17:28:47 kelWEB4 su: PAM (su-l) no module name supplied

2.2 解决方法

       查看配置文件中包含此关键字的文件,使用命令如下:

@kelWEB4:/etc# find ./* -name \* -type f -print|xargs grep "minlen"./pam.d/system-auth-ac:password    requisite     pam_cracklib.so try_first_pass retry=3 type=  minlen=8 minclass=2

可以发现文件为

@kelWEB4:/etc# ll -d /etc/pam.d/system-auth-ac -rw-r--r-- 1 root root 958 May 23 11:41 /etc/pam.d/system-auth-ac


查看里面的配置,看此行是否存在换行的错误,如果存在换行,那么将必然报错,此服务器报错,是因为在type后进行了换行,从而导致了错误的发生。

3、 可能的报错

Ø  在非同网段远程连接的时候,显示是可以登录,但是Connection closed by foreignhost

Ø  在同网段远程连接的时候,显示connection reset bypeer

Ø  还有看到错误could not open session

Ø  注意检查是否开启22端口,使用




0 0