在Centos 6.6 中ssh出现Connection to localhost closed by remote host的问题排查

摘要:
在Docker中运行ssh时会出现问题。该问题的初始特征是1bash-4.1#sshlocalhost2连接到本地主机closedbyremotehost。在问题解决过程中,我们首先检查了sshd的启动。似乎已经启动了1bash-4.1#psax|grepsshd233?Ss0:00/usr/sbin/sshd3870?S+0:00grepsshd搜索了

问题出现

这是在Docker中运行ssh中出现的问题,问题初始特征表现为

1 bash-4.1# ssh localhost
2 Connection to localhost closed by remote host.

问题解决过程

首先查看了sshd的启动情况,看似已经启动了

1 bash-4.1# ps ax |  grep sshd
2    33 ?        Ss     0:00 /usr/sbin/sshd
3   870 ?        S+     0:00 grep sshd

在搜索了网上的一些资料后,怀疑是因为SELINUX的原因引起的,因此运行了getenforce

1 bash-4.1# getenforce
2 getenforce:  getenforce() failed

发现不能使用getenforce命令获得SELINUX的状态,我也运行了ssh -v localhost查看详细原因

 1 bash-4.1# ssh localhost -v
 2 OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
 3 debug1: Reading configuration data /root/.ssh/config
 4 debug1: Applying options for *
 5 debug1: Reading configuration data /etc/ssh/ssh_config
 6 debug1: Applying options for *
 7 debug1: Connecting to localhost [::1] port 2122.
 8 debug1: Connection established.
 9 debug1: permanently_set_uid: 0/0
10 debug1: identity file /root/.ssh/identity type -1
11 debug1: identity file /root/.ssh/identity-cert type -1
12 debug1: identity file /root/.ssh/id_rsa type 1
13 debug1: identity file /root/.ssh/id_rsa-cert type -1
14 debug1: identity file /root/.ssh/id_dsa type -1
15 debug1: identity file /root/.ssh/id_dsa-cert type -1
16 debug1: identity file /root/.ssh/id_ecdsa type -1
17 debug1: identity file /root/.ssh/id_ecdsa-cert type -1
18 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
19 debug1: match: OpenSSH_5.3 pat OpenSSH*
20 debug1: Enabling compatibility mode for protocol 2.0
21 debug1: Local version string SSH-2.0-OpenSSH_5.3
22 debug1: SSH2_MSG_KEXINIT sent
23 debug1: SSH2_MSG_KEXINIT received
24 debug1: kex: server->client aes128-ctr hmac-md5 none
25 debug1: kex: client->server aes128-ctr hmac-md5 none
26 debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
27 debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
28 debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
29 debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
30 debug1: checking without port identifier
31 Warning: Permanently added '[localhost]:2122' (RSA) to the list of known hosts.
32 debug1: ssh_rsa_verify: signature correct
33 debug1: SSH2_MSG_NEWKEYS sent
34 debug1: expecting SSH2_MSG_NEWKEYS
35 debug1: SSH2_MSG_NEWKEYS received
36 debug1: SSH2_MSG_SERVICE_REQUEST sent
37 debug1: SSH2_MSG_SERVICE_ACCEPT received
38 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
39 debug1: Next authentication method: gssapi-keyex
40 debug1: No valid Key exchange context
41 debug1: Next authentication method: gssapi-with-mic
42 debug1: Unspecified GSS failure.  Minor code may provide more information
43 Credentials cache file '/tmp/krb5cc_0' not found
44 
45 debug1: Unspecified GSS failure.  Minor code may provide more information
46 Credentials cache file '/tmp/krb5cc_0' not found
47 
48 debug1: Unspecified GSS failure.  Minor code may provide more information
49 
50 
51 debug1: Unspecified GSS failure.  Minor code may provide more information
52 Credentials cache file '/tmp/krb5cc_0' not found
53 
54 debug1: Next authentication method: publickey
55 debug1: Trying private key: /root/.ssh/identity
56 debug1: Offering public key: /root/.ssh/id_rsa
57 debug1: Server accepts key: pkalg ssh-rsa blen 277
58 debug1: read PEM private key done: type RSA
59 debug1: Authentication succeeded (publickey).
60 debug1: channel 0: new [client-session]
61 debug1: Requesting no-more-sessions@openssh.com
62 debug1: Entering interactive session.
63 debug1: channel 0: free: client-session, nchannels 1
64 Connection to localhost closed by remote host.
65 Connection to localhost closed.
66 Transferred: sent 2344, received 2128 bytes, in 0.0 seconds
67 Bytes per second: sent 23187378.7, received 21050657.8
68 debug1: Exit status -1

按照debug的出错信息,我又继续搜索,在这里发现了出现同样问题的帖子,帖子的最后说在更新了yum后问题消失了,我也试了试

1 bash-4.1# yum update

然后再运行ssh localhost

1 bash-4.1# ssh localhost
2 Last login: Fri Dec  5 01:15:04 2014 from localhost
3 -bash-4.1#

一切正常了,问题成功解决。特此记录下排查过程。

免责声明:文章转载自《在Centos 6.6 中ssh出现Connection to localhost closed by remote host的问题排查》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SQL Server游标的使用 转无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败。下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Centos设置串口波特率

1、stty查看串口参数 stty -F /dev/ttyS0 -a查看串口1(/dev/ttyS0)当前的参数,包括波特率、数据位等。 2、stty设置串口参数 stty -F /dev/ttyS0 ispeed 115200 ospeed 115200 cs8 该命令将串口1(/dev/ttyS0)设置成115200波特率,8位数据模式。一般情况下设置...

制作centos的U盘启动盘

制作centos的U盘启动盘比ubuntu麻烦一些,因为可能涉及到fat32文件格式不支持大于4G的文件存储的问题,而最新版本的centos就是大于4G的,所以就需要对U盘进行分区. 一个做主引导,一个为逻辑分区,基本概念同电脑硬盘的分区概念相同,主引导分区我这里仍然为fat32格式,用于使用ultralISO制作U盘启动到这里,然后在copy DVD1到...

Ubuntu14.04或16.04下安装JDK1.8+Scala+Hadoop2.7.3+Spark2.0.2

为了将Hadoop和Spark的安装简单化,今日写下此帖。 首先,要看手头有多少机器,要安装伪分布式的Hadoop+Spark还是完全分布式的,这里分别记录。 1. 伪分布式安装 伪分布式的Hadoop是将NameNode,SecondaryNameNode,DataNode等都放在一台机器上执行,Spark同理,一般用于开发环境。 1.1 准备工作 系统...

Linux(Ubuntu):搭建GitLab托管代码

GitLab 简介: GitLab 是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的 Git 项目仓库,可通过 Web 界面进行访问公开的或者私人项目。它拥有与 Github 类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序...

ssh分发秘钥时出现错误“Permission denied (publickey,gssapi-keyex,gssapi-with-mic)”

因为公司的服务器连接是通过xshell公钥和密码连接的,今天在ssh分发秘钥的时候出现了,下面的错误: [root@iZ2ze97cumk8opqm28h8Z .ssh]# ssh-copy-id -i /root/.ssh/id_dsa.pub "root@123.56.82.168 -p 52808" Permission denied (publi...

ansible(一)

Ansible简介 Ansible:Ansible的核心程序Host Lnventory:记录了每一个由Ansible管理的主机信息,信息包括ssh端口,root帐号密码,ip地址等等。可以通过file来加载,可以通过CMDB加载。Playbooks:YAML格式文件,多个任务定义在一个文件中,使用时可以统一调用,“剧本”用来定义那些主机需要调用那些模块来...