![使用 ssh 密钥进行多用户登录的 AWS ec2 实例不起作用](https://linux22.com/image/1623632/%E4%BD%BF%E7%94%A8%20ssh%20%E5%AF%86%E9%92%A5%E8%BF%9B%E8%A1%8C%E5%A4%9A%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E7%9A%84%20AWS%20ec2%20%E5%AE%9E%E4%BE%8B%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我在 aws ec2 中有一个服务器(ubuntu16.04)。我有一个访问该服务器的私钥。我使用的原始用户名为ubuntu
由 aws 生成的。现在我的客户端 B 想要登录服务器进行同步(它是一台 windows10 pc)。我不想在不同的地方使用我的 aws 私钥。所以我创建了一个具有有限权限的新用户,名为syncusr
。
$ cat /etc/passwd
syncusr:x:1002:1002::/home/syncusr:
我生成了 ssh-key(ssh-keygen),然后将公钥附加到 ~/.ssh 中的 authorized_keys
$ ls -ld ~/.ssh; ls -l ~/.ssh
drwx------ 2 syncusr syncusr 4096 May 15 12:14 /home/syncusr/.ssh
total 8
-rw-r--r-- 1 syncusr syncusr 404 May 15 12:13 authorized_keys
-rwxrwxrwx 1 syncusr syncusr 1679 May 15 12:13 id_rsa
现在我下载 id_rsa 并运行 PuTTYgen 获得私钥,然后我使用用户名 syncusr 和私钥从客户端 B 登录但失败了。
. 2020-05-15 12:17:00.335 Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
. 2020-05-15 12:17:00.335 Initialised HMAC-SHA-256 outbound MAC algorithm
. 2020-05-15 12:17:00.335 Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
. 2020-05-15 12:17:00.335 Initialised HMAC-SHA-256 inbound MAC algorithm
. 2020-05-15 12:17:00.507 Reading key file "D:\SSHKEY\private_key.ppk"
! 2020-05-15 12:17:00.507 Using username "syncusr".
. 2020-05-15 12:17:00.709 Server offered these authentication methods: publickey
. 2020-05-15 12:17:00.709 Offered public key
! 2020-05-15 12:17:00.901 Server refused our key
. 2020-05-15 12:17:00.918 Server refused our key
. 2020-05-15 12:17:00.918 Server offered these authentication methods: publickey
. 2020-05-15 12:17:00.918 No supported authentication methods available (server sent: publickey)
. 2020-05-15 12:17:00.918 Attempt to close connection due to fatal exception:
* 2020-05-15 12:17:00.918 No supported authentication methods available (server sent: publickey)
我错过了哪一部分?
解决方案:
drwx------ 2 /home/sync1/.ssh
total 8
-rw-r--r-- 1 authorized_keys
-rw------- 1 id_rsa