SSH到本地主机显示“由远程主机关闭连接”

问题描述:

我已经安装并正在运行ssh。我跑了sudo chmod -R 777 /var并停止工作。我更改了sudo chmod -R 700 /var的权限,但这并没有让它再次运行。SSH到本地主机显示“由远程主机关闭连接”

当我做ssh -v localhost我得到这样的输出:

[email protected]:/$ ssh -v localhost 
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010 
debug1: Connecting to localhost [127.0.0.1] port 22. 
debug1: Connection established. 
debug1: identity file /home/rajat/.ssh/id_rsa type -1 
debug1: identity file /home/rajat/.ssh/id_rsa-cert type -1 
debug1: identity file /home/rajat/.ssh/id_dsa type -1 
debug1: identity file /home/rajat/.ssh/id_dsa-cert type -1 
debug1: identity file /home/rajat/.ssh/id_ecdsa type -1 
debug1: identity file /home/rajat/.ssh/id_ecdsa-cert type -1 
ssh_exchange_identification: Connection closed by remote host 
[email protected]:/$ 
+0

获得的经验教训:不要那么血腥。为什么在地球上搞乱'/ var'的权限不会破坏事情,你怎么觉得把它们搞乱会有所帮助? – tripleee 2012-01-30 21:39:05

OpenSSH是非常挑剔的,当涉及到的文件和目录的权限和所有权。至少在RHEL/CentOS上,它所接触的/var下的唯一目录是/var/empty/sshd目录,如果UsePrivilegeSeparation设置为yes,它将执行chroot

设置这在您的sshd_config文件:

UsePrivilegeSeparation no 

,并重新启动sshd的,看看它是否工作。如果那样做的话,那很可能是导致问题的/var/empty/sshd上的权限/所有权。

+1

嗯,你回复得太晚了:(但是幸运的是我在一台虚拟机(vmware)中工作,最后我把所有的工作都复制到了一个版本库,然后在虚拟机上恢复一个快照,并执行'svn update'但因为这是唯一的答案,所以我要标记它是正确的。 – prongs 2012-01-09 10:56:58

如果有人在尝试连接到在VirtualBox上运行的Ubuntu VM时遇到类似的错误消息,请在网络设置中将第二个网络适配器设置为“桥接”,并将“NAT”上的端口转发设置为22.