CentOS 7.6出现SSH登录失败的解决方法

CentOS 7.6出现SSH登录失败的解决方案

问题重现:

iterm登录

1
2
3
4
5
6
ssh vagrant@192.168.10.10
The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.
ECDSA key fingerprint is SHA256:8nyfIaEq9jMHfb9aQIlPh5OAGXjjSVGEDiXfMjlD7H8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.
vagrant@192.168.10.10: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

sshShell登录

1
2
3
4
5
6
7
8
9
10
>   11:06:29 Connecting to 192.168.10.10 port 22
> 11:06:29 Command: ssh -p 22 vagrant@192.168.10.12
> 11:06:29 Connect to 192.168.10.12:22, with timeout 15.000000
> 11:06:29 Create socket with IPv4 address family
> 11:06:29 Socket is connected successfully
> 11:06:29 Client banner: SSH-2.0-libssh_0.7.5
> 11:06:29 Server banner: SSH-2.0-OpenSSH_7.4
> 11:06:29 Negotiated with server
> 11:06:29 Authentication that can continue: publickey, gssapi-with-mic
> 11:06:29 Disconnected from server

解决办法

1、卸载重新

1
2
[root@cent ~]# yum -y remove openssh-server
[root@cent ~]# yum -y install openssh-server

2、生成密钥(可选)

1
[root@cent ~]# sshd-keygen

3、修改sshd_config配置文件

1
[root@cent ~]# vim /etc/ssh/sshd_config
1
2
# 添加以下内容至文件末尾处 :wq
PubkeyAuthentication yes

4、重新启动sshd

1
[root@cent ~]# systemctl restart sshd.service