我正在使用 Ubuntu 15.10,尽管我添加了 ssh 密钥,但我还是无法通过 ssh 无密码登录。它之前可以正常工作,然后突然停止工作。我不知道我到底做了什么让它停止工作。你能帮我解决这个问题吗?有没有办法重置所有内容并从头开始?
在尝试修复它时,我运行了以下两个命令几次,但没有成功:
ssh-keygen -t rsa
ssh-copy-id myusername@remotehost
现在我在远程机器上执行以下操作:
cat authorized_keys
它给了我三把钥匙。
在客户端机器上:这是我对 .ssh 文件夹的权限:
drwx------ 2 user user 4096 Apr 18 09:44 .ssh
该文件夹内的权限如下:
-rw------- 1 user user 822 Apr 15 13:08 authorized_keys
-rw------- 1 user user 1679 Apr 18 09:44 id_rsa
-rw-r--r-- 1 user user 411 Apr 18 09:44 id_rsa.pub
-rw-r--r-- 1 user user 2335 Apr 14 16:06 known_hosts
详细输出如下:
$ ssh -v user@localhost
OpenSSH_6.9p1 Ubuntu-2ubuntu0.1, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9p1 Ubuntu-2ubuntu0.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.9p1 Ubuntu-2ubuntu0.1
debug1: match: OpenSSH_6.9p1 Ubuntu-2ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:/CGAtknCe0ao9c+ZRoBDrbdBEaoweEKCtN0r+gO9Nyg
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:6
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Trying private key: /home/user/.ssh/id_ed25519
debug1: Next authentication method: password
我刚刚注意到了这一点,并且认为这将是某件事的暗示:
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
42 debug1: Server accepts key: pkalg ssh-rsa blen 279 42 debug1: Server accepts key: pkalg ssh-rsa blen 279
43 debug1: Trying private key: /home/user/.ssh/id_dsa 43 debug1: Trying private key: /home/user/.ssh/id_dsa
44 debug1: Trying private key: /home/user/.ssh/id_ecdsa 44 debug1: Trying private key: /home/user/.ssh/id_ecdsa
45 debug1: Trying private key: /home/user/.ssh/id_ed25519 45 debug1: Trying private key: /home/user/.ssh/id_ed25519
我的 .ssh 文件夹中没有这些文件,但我有:
-rw------- 1 user user 1233 Apr 18 12:31 authorized_keys
-rw------- 1 user user 1679 Apr 18 09:44 id_rsa
-rw-r--r-- 1 user user 411 Apr 18 09:44 id_rsa.pub
-rw-r--r-- 1 user user 2335 Apr 14 16:06 known_hosts
谢谢
答案1
我找到的解决方案有点极端,但解决了这个问题:
sudo apt-get --purge remove openssh-client openssh-server
然后重命名我的 .ssh 文件夹,并从头开始。这解决了我的本地主机连接以及我正在使用的其他远程服务器的问题。显然,我必须将公钥复制到所有机器上。
谢谢