【问题标题】:trouble connecting to AWS Lightsail via SSH with keys other than default使用非默认密钥通过 SSH 连接到 AWS Lightsail 时出现问题
【发布时间】:2020-09-24 17:46:03
【问题描述】:

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

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: curve25519-sha256@libssh.org 
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com  MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com  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.
me@x.x.x.x : Permission denied (publickey).

我必须在 SSH 密钥屏幕上错过一个步骤,但我似乎无法弄清楚它会是什么。有人可以帮忙吗?

【问题讨论】:

    标签: amazon-web-services ssh private-key amazon-lightsail


    【解决方案1】:

    密钥对是 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 文件中。但是,您需要为已运行的实例手动执行此步骤。

    【讨论】:

    • 哇!我不知道为什么我不只是想为我试图授予访问权限的新用户添加一个 authorized_keys 文件。这一切都很好 - 谢谢!我想我真正不明白通过 Lightsail 控制台上传和/或添加新密钥的所有工作原理。我有点认为他们需要您通过该 GUI 添加密钥(就像我的托管 Wordpress 主机一样),但显然情况并非如此。问题解决了,但仍然很困惑。
    【解决方案2】:

    对于 AWS Lightsail,我可以通过 SSH 登录,方法是将我的公钥 id_rsa.pub 附加到远程授权密钥,我使用 SFTP (Filezilla) 更新授权密钥文件。对于 SFTP 连接,我从 Accounts 页面下载了 ssh 密钥。

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 2012-07-01
      • 2021-06-18
      • 2013-10-29
      • 1970-01-01
      • 2019-07-10
      • 2017-04-17
      • 1970-01-01
      • 2023-03-08
      相关资源
      最近更新 更多