centos无法通过ssh连接的解决

系统环境是centos7,虚拟机环境下的。在使用ssh工具连接虚拟机的时候发现连接不上,用的是root

先检查openssh-server是否安装:

yum list installed | grep openssh-server

查看日志/var/log/secure:

显示相关的错误内容:

PAM  1  more  authentication  failure;  logname =uid=0  euid=0  tty=ssh  ruser=  rhost=……

pam_unix(login:session) :session  closed  for  user  root

没有发现什么有用的信息

查看22端口是否开启监听:

netstat  -an |  grep  22

发现没有listen,那么就是配置文件的问题了,

打开/etc/ssh/sshd_config

将选项中的Port  22取消注释,还有ListenAddress  0.0.0.0   ListenAddress  ::也取消注释,这些设置分别为监听端口、监听地址

PermitRootLogin  no  的no改为yes(允许root开启远程登录)

PasswordAuthentication  设置为yes(开启使用用户名和密码作为连接验证)

(如果是ubuntu,找到 GSSAPI options 这一节,将下面两行注释掉:
  #GSSAPIAuthentication yes #GSSAPIDelegateCredentials no     然后重新启动)

退出后重启sshd,service  sshd  restart

同时要确保虚拟机系统和主机是通过局域网下的,能互相ping通的

将ssh设为自启动:

systemctl enable sshd.service

检测ssh是否为自启动:

systemctl list-unit-files | grep sshd

Technorati Tags:

参考:http://m.blog.csdn.net/article/details?id=52755571

原文地址:https://www.cnblogs.com/simonid/p/6442741.html