在 Mac 上通过终端连接到 EC2 实例
Posted
技术标签:
【中文标题】在 Mac 上通过终端连接到 EC2 实例【英文标题】:Connecting to EC2 Instance via Terminal on Mac 【发布时间】:2013-09-22 12:41:32 【问题描述】:我对编码完全陌生,正在 coursera 上开设一个创业课程:https://class.coursera.org/startup-001/lecture/87
我在尝试连接到我在 AWS 上创建的 EC2 Ubuntu 实例时收到权限被拒绝(公钥)
-
设置 AWS Istance
将安全设置为默认并添加端口 22 并启动
课程告诉我然后输入:
chmod 400 trevor-learning.pem ssh -i trevor-learning.pem \ec2-user@ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com
这给了我这个错误:权限被拒绝(公钥)。
我查看了其他问题并尝试将 ubuntu@ 切换到 ec2-user 和其他一些东西,但我仍然无法连接。
我也试过: trevor-larsons-macbook-pro:下载trev$ chmod 600 trevor-learning.pem trevor-larsons-macbook-pro:下载trev$ ssh -v -i trevor-learning ubuntu@ec2-XX-XXX-XX- XX.us-west-2.compute.amazonaws.com
这给了我:
OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
Warning: Identity file trevor-learning not accessible: No such file or directory.
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com [XX.XXX.XX.XX] port 22.
debug1: Connection established.
debug1: identity file /Users/trev/.ssh/id_rsa type -1
debug1: identity file /Users/trev/.ssh/id_rsa-cert type -1
debug1: identity file /Users/trev/.ssh/id_dsa type -1
debug1: identity file /Users/trev/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
debug1: Host 'ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/trev/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/trev/.ssh/id_rsa
debug1: Trying private key: /Users/trev/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
在这里不知所措,不知道我在做什么,请帮忙!
另外,不确定这是否与它有关,当我下载实例证书时(显示在 chrome 浏览器的左下角,它打开了我的钥匙串访问权限并说“发生错误。无法导入项目. 无法检索此项目的内容。"
【问题讨论】:
需要注意的错误是这样的:Warning: Identity file trevor-learning not accessible: No such file or directory.
@datasage 我真的不明白我在做什么。该文件在我的下载文件夹中。我转到终端中的目录,然后从那里完成其余的工作。它最终问:无法确定主机'ec2-XX-XXX-XX-XXX.us-west-2.compute.amazonaws.com(XX.XXX.XX.XXX)'的真实性。 RSA 密钥指纹为 2f:71:6a:82:4d:ec:29:a2:eb:12:96:f3:09:17:71:e1。您确定要继续连接(是/否)?是 警告:将“ec2-XX-XXX-XX-XXX.us-west-2.compute.amazonaws.com,XX.XXX.XX.XX”(RSA)永久添加到已知主机列表中。权限被拒绝(公钥)。
【参考方案1】:
在您的终端中尝试以下步骤:
ssh-keygen -R 12.345.678.999 // This Reset your publickey
然后尝试使用 EC2 的 Key Pair Name 和 Public DNS 访问:
ssh -i KeyPairName.pem ubuntu@ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
【讨论】:
太感谢你了!!老实说,去掉 KeyPairName 和 ubuntu@ 之间的“\”是诀窍,不知道为什么,但谢谢!! \ 字符通常用于表示由于宽度限制而必须换行到下一行的长命令(即,如果打印在书籍或在线教程中)时的连续行。它并不是要输入的,但通常,如果您将其复制并粘贴到终端中,终端将忽略它并正确执行命令。在wikipedia article 上查看更好的解释以上是关于在 Mac 上通过终端连接到 EC2 实例的主要内容,如果未能解决你的问题,请参考以下文章