通过SSH连接到AWS Lightsail时,除了默认的密钥外,还遇到了麻烦。

问题描述 投票:0回答:1

我已经下载了默认的私钥,并且能够通过SSH连接,使用该私钥没有问题。在我的Lightsail实例中,我进入SSH密钥选项卡,创建了一个新的密钥对,并下载了新的私钥(将其保存在我的本地机器上的正确位置,并有适当的权限)。然而,我无法使用新的私钥进行连接。以下是我从命令中得到的输出。 ssh -v -i ~/.ssh/test.pem [email protected]

OpenSSH_7.8p1, LibreSSL 2.6.2
debug1: Reading configuration data /Volumes/Norman Data/daveh0/.ssh/config
debug1: /Volumes/Norman Data/daveh0/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to x.x.x.x port 22.
debug1: Connection established.
debug1: identity file .ssh/test.pem type -1
debug1: identity file .ssh/test.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to x.x.x.x:22 as 'me'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected] 
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: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:Bajjqc9SJlMHTB/OrEWKl4ATi6/wI+fB1C351fi5Iwk
debug1: Host 'x.x.x.x' is known and matches the ECDSA host key.
debug1: Found key in /Volumes/Norman Data/daveh0/.ssh/known_hosts:10
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: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: .ssh/test.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
[email protected] : Permission denied (publickey).

我在SSH密钥屏幕上少了一个步骤 但我似乎不知道那是什么。有人能帮忙吗?

amazon-web-services ssh private-key amazon-lightsail
1个回答
0
投票

密钥对是Linux的一个特性。它的工作方式是。

  • 有人试图用SSH连接到Linux电脑上,比如说 ssh -i key.pem username@IP-ADDRESS
  • Linux电脑的外观在 /home/USERNAME/.ssh/authorized_keys
  • 如果它找到了一个与提供的私钥相匹配的公钥。key.pem,则允许连接

因此,由于您创建了一个新的密钥对,您将需要 将新的密钥对添加到相应用户的 ~/.ssh/authorized_keys 档案.

你的例子显示你是以一个叫做 me,所以公钥对应该被添加到 /home/me/.ssh/authorized_keys.

当第一次启动Lightsail或EC2实例时,你可以指定一个密钥对,实例上的软件会自动将相关的公钥添加到? authorized_keys 文件,但对于已经运行的实例,您需要手动执行这一步。但是,对于已经运行的实例,您需要手动执行此步骤。

© www.soinside.com 2019 - 2024. All rights reserved.