ssh免密登录失败

前言

本来要在服务器上安装docker-machine,然后管理其他云服务器的docker容器的,结果到了ssh免密登录这一步,一直走不通。下面把我遇到的问题,记录下。

注:docker-machine安装可参考文章:https://blog.csdn.net/wfs1994/article/details/80658555

ssh免密登录

由于,要管理其他的云服务器的docker,所以需要用ssh免密登录到其余的云服务器(主服务器192.168.20.200,远程服务器192.168.20.201)。如下:

ssh-keygen -t rsa

ssh-copy-id 192.168.20.201

然后输入192.168.20.201的密码,提示ok了,于是测试下

ssh 192.168.20.201

结果还是需要输入密码。

google一下

出现这种奇葩问题,果断,先google一下。结果大部分都说是权限问题,然后我按照教程说的修改了192.168.20.201下root目录及下面的.ssh文件夹的权限,还是不行。

于是用ssh -v 192.168.20.201看一下日志:
 

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 192.168.20.201 [192.168.20.201] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.20.201:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:wORn5yWtd8wO3XfFm11Wu6iNezHNRT5QKxowGHZyCT0
debug1: Host '192.168.20.201' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)

debug1: Next authentication method: password

发现ssh确实是几种认证方式都失败了,直接到了需要密码登录,如下:

那这是什么原因造成的呢?

结果发现认证方式只有gssapi-keyex,gssapi-with-mic,password,并没有publickey。

那肯定是192.168.20.201这台服务器上的sshd配置有问题。

于是登录192.168.20.201这台服务器,看了下sshd配置

搜索PubkeyAuthentication,结果发现这项被注释了。放开注释,重启sshd:service sshd restart。

再用ssh远程登录这台服务器,ok了。

猜你喜欢

转载自blog.csdn.net/maquealone/article/details/84110482