1.问题描述
ssh服务安装好后,测试服务也是启动了的。但用putty连接就是不行,直接报错:server unexpectedly closed network connection
然后登陆linux服务器直接测试: ssh localhost也是报错:
read from socket failed connection reset by peer
2.解决办法
查资料,查看防火墙,查看/etc/ssh/ssh_config都没有问题。在win7上用telnet IP 22测试也没问题。
最后在
http://askubuntu.com/questions/308107/cant-ssh-localhost上看到解答,虽然ssh_config文件没问题,但是/etc/ssh/sshd_config文件是空的。按步骤:
1.Remove the configuration file:
sudo rm /etc/ssh/sshd_config
2.purge:
sudo apt-get purge openssh-server
3.install:
sudo apt-get install openssh-server
完成上面三步再看sshd_config文件就不是空的了。再用service ssh status查看也没问题。
4.用ssh localhost没问题了! 用pietty登陆也没问题。
注意:此时都是用的普通用户登陆。用root用户两种方式都不行。用pietty可以先用普通用户登陆然后再切换到root。
2.1 root登陆
我们还是想能直接用root用户登陆。可以参考:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/V2V_Guide/Preperation_Before_the_P2V_Migration-Enable_Root_Login_over_SSH.html
Enable root login over SSH:
As root, edit the sshd_config file in /etc/ssh/sshd_config:
vi /etc/ssh/sshd_config
(1)Add a line in the Authentication section of the file that says PermitRootLogin yes. This line may already exist and be commented out with a "#". In this case, remove the "#".
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
(2)Save the updated /etc/ssh/sshd_config file.
(3)Restart the SSH server:
(4)service ssh restart // 这个事ubuntu,其他linux可能是service sshd restart
好了,测试通过。
<ssh> 2 putty无法连接ubuntu
猜你喜欢
转载自zoroeye.iteye.com/blog/2101529
今日推荐
周排行