AWS ssh 访问“权限被拒绝(公钥)”问题

发布于 2024-08-05 12:22:36 字数 1549 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(20

旧时模样 2024-08-12 12:22:36

对于 Ubuntu 实例:

chmod 600 ec2-keypair.pem
ssh -v -i ec2-keypair.pem [email protected]

对于其他实例,您可能必须使用 ec2-user 而不是 ubuntu

我使用过的大多数 EC2 Linux 映像仅默认创建 root 用户。

另请参阅:http://www.youtube.com/watch?v=WBro0TEAd7g

For Ubuntu instances:

chmod 600 ec2-keypair.pem
ssh -v -i ec2-keypair.pem [email protected]

For other instances, you might have to use ec2-user instead of ubuntu.

Most EC2 Linux images I've used only have the root user created by default.

See also: http://www.youtube.com/watch?v=WBro0TEAd7g

染年凉城似染瑾 2024-08-12 12:22:36

现在是:

ssh -v -i ec2-keypair.pem ec2-user@[yourdnsaddress]

Now it's:

ssh -v -i ec2-keypair.pem ec2-user@[yourdnsaddress]
简单 2024-08-12 12:22:36

Canonical 的发行版默认使用用户“ubuntu”,任何使用 ubuntu 映像登陆此处但遇到相同问题的人都可以使用该用户。

Canonical's releases use the user 'ubuntu' by default for anyone landing here with a ubuntu image that is coming up with the same problem.

茶花眉 2024-08-12 12:22:36

如果您使用的是 Bitnami 图像,请以“bitnami”身份登录。

看起来很明显,但我忽略了一些事情。

If you're using a Bitnami image, log in as 'bitnami'.

Seems obvious, but something I overlooked.

葬心 2024-08-12 12:22:36

对于我的 ubuntu 映像,它实际上是 ubuntu 用户而不是 ec2 用户;)

For my ubuntu images, it is actually ubuntu user and NOT the ec2-user ;)

李白 2024-08-12 12:22:36

如果您正在运行 Bitnami 的 AWS 映像。用户名是bitnami。干杯!

查看我的调试并查看最后一个

**

ssh -v -i awsliferaysrta.pem.txt [email protected].***
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 54.254.250.*** [54.254.250.***] port 22.
debug1: Connection established.
debug1: identity file awsliferaysrta.pem.txt type -1
debug1: identity file awsliferaysrta.pem.txt-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH_5*
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 05:5c:78:45:c9:39:3a:84:fe:f8:19:5d:31:48:aa:5f
debug1: Host '54.254.250.***' is known and matches the RSA host key.
debug1: Found key in /Users/macbookpro/.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: awsliferaysrta.pem.txt
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to 54.254.250.*** ([54.254.250.***]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Remote: Port forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Forced command.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Please login as the user "bitnami" rather than the user "root".

If you are running AWS image from Bitnami. The username would be bitnami. Cheers!

see my debug and look at the last one:

*

ssh -v -i awsliferaysrta.pem.txt [email protected].***
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 54.254.250.*** [54.254.250.***] port 22.
debug1: Connection established.
debug1: identity file awsliferaysrta.pem.txt type -1
debug1: identity file awsliferaysrta.pem.txt-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH_5*
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 05:5c:78:45:c9:39:3a:84:fe:f8:19:5d:31:48:aa:5f
debug1: Host '54.254.250.***' is known and matches the RSA host key.
debug1: Found key in /Users/macbookpro/.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: awsliferaysrta.pem.txt
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to 54.254.250.*** ([54.254.250.***]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Remote: Port forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Forced command.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Please login as the user "bitnami" rather than the user "root".

*

花期渐远 2024-08-12 12:22:36

使用 openSSH 的 Ubuntu 10.04

这是确切的用法:

ssh -v -i [yourkeypairfile] ec2-user@[yourdnsaddress]

例如:

ssh -v -i GSG_Keypair.pem [email protected]

上面的示例直接取自 AWS 连接到 Linux/UNIX 机器的教程,网址为:
http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/

Ubuntu 10.04 with openSSH

this is the exact usage:

ssh -v -i [yourkeypairfile] ec2-user@[yourdnsaddress]

for example:

ssh -v -i GSG_Keypair.pem [email protected]

above example was taken directly from the AWS tutorial for connecting to a Linux/UNIX machine at:
http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/

小草泠泠 2024-08-12 12:22:36

如果 pem 文件权限过于开放,它也会抱怨。 chmod 文件到 600 来解决这个问题。

It will also complain if the pem file permissions are too open. chmod the file to 600 to fix that.

鹤舞 2024-08-12 12:22:36

我也遇到了这个问题 - 结果我使用的是社区创建的 AMI - 默认用户名是 niehter root,也不是 ect-user 或 ubuntu。事实上,我不知道它是什么 - 直到我尝试“root”,服务器友好地要求我以 xxx 身份登录,其中 xxx它告诉你什么。

-干杯!

I was also running into this - turns out I was using a community-created AMI - and the default username was niehter root, nor was it ect-user or ubuntu. In fact, I had no idea what it was - till I tried 'root' and the server kindly asked me to login as xxx where xxx is whatever it tells you.

-cheers!

地狱即天堂 2024-08-12 12:22:36

您需要在本地计算机中拥有您的私钥

您需要知道远程计算机或服务器的 IP 地址或 DNS 名称,您可以从 AWS 控制台获取此信息

如果您是 Linux 用户

  • 请确保私钥的权限为 600
    chmod 600 <私钥文件的路径>
  • 使用 ssh 连接到您的计算机
    (ssh -i <私钥文件的路径> <用户>@<远程服务器的 IP 地址或 DNS 名称>)

如果您是 Windows 用户

You need have your private key in your local machine

You need to know the IP address or DNS name of your remote machine or server, you can get this from AWS console

If you are a linux user

  • Make sure the permissions on the private key are 600
    (chmod 600 <path to private key file>)
  • Connect to your machine using ssh
    (ssh -i <path to private key file> <user>@<IP address or DNS name of remote server>)

If you are a windows user

秉烛思 2024-08-12 12:22:36

使用...

# chmod 400 ec2-keypair.pem

不要使用 600 权限,否则您可能会意外覆盖您的密钥。

use...

# chmod 400 ec2-keypair.pem

don't use the 600 permission otherwise you might overwrite your key accidently.

眼泪淡了忧伤 2024-08-12 12:22:36

对于 Debian EC2 实例,用户是 admin

For Debian EC2 instances, the user is admin.

も让我眼熟你 2024-08-12 12:22:36

连接有 2 个步骤:

对您的私钥进行 Chmod 400,这样其他人就无法访问您的密钥:

chmod 400 toto.pem

要通过 SSH 连接到您的实例,您需要知道实例的公共 IP 地址:

ssh -i toto.pem [email protected]

希望它有帮助!

There are 2 steps to be connected:

Chmod 400 on your private key, like this the others cannot access to your key:

chmod 400 toto.pem

To connect to your instance in SSH, you need to know the public IP address of your instance :

ssh -i toto.pem [email protected]

Hope it helps !

×纯※雪 2024-08-12 12:22:36

这对我有用:

ssh-keygen -R <server_IP>

删除工作站上存储的旧密钥
也可以使用而不是

再次执行相同的 ssh 它有效:

ssh -v -i <your_pem_file> ubuntu@<server_IP>

在 ubuntu 实例上,用户名是:ubuntu
在 Amazon Linux AMI 上,用户名是:ec2-user

我不必从映像重新创建实例。

this worked for me:

ssh-keygen -R <server_IP>

to delete the old keys stored on the workstation
also works with instead of

then doing the same ssh again it worked:

ssh -v -i <your_pem_file> ubuntu@<server_IP>

on ubuntu instances the username is: ubuntu
on Amazon Linux AMI the username is: ec2-user

I didn't have to re-create the instance from an image.

墨小墨 2024-08-12 12:22:36

ec2-keypair.pem 的权限应为 400

chmod 400 ec2-keypair.pem

Permission for ec2-keypair.pem should be 400

chmod 400 ec2-keypair.pem

尐偏执 2024-08-12 12:22:36

如果您使用的是 EBS,您还可以尝试在正在运行的实例上挂载 EBS 卷。然后将其安装到正在运行的实例上并查看 /home 中发生了什么。您可以看到诸如用户是 ubuntu 还是 ec2-user 之类的内容?或者它在 ~/.ssh/authorized_keys 下是否有正确的公钥

If you are using EBS, you can also try to mount the EBS Volume on a running instance. Then mount it on that running instance and see what's going on in /home. You can see things like is the user ubuntu or ec2-user ? or does it have the right public keys under ~/.ssh/authorized_keys

玩世 2024-08-12 12:22:36

就我而言(Mac OS X),问题在于文件的中断类型。试试这个:

1.- 使用 TextWrangler 打开 .pem 文件

2.- 在应用程序底部,验证中断类型是否为“Windows(CRLF)”。

In my case (Mac OS X), the problem was the file's break type. Try this:

1.- Open the .pem file with TextWrangler

2.- At Bottom of app, verify if the Break Type is "Windows(CRLF)".

ゝ杯具 2024-08-12 12:22:36

它的 ec2-user 用于 Amazon Linux AMI,而 ubuntu 用于 Ubuntu 映像。
此外,RHEL 6.4 及更高版本 ec2-user
RHEL 6.3 及更早版本 root
Fedora ec2-用户
Centos 根

Its ec2-user for Amazon Linux AMI's and ubuntu for Ubuntu images.
Also, RHEL 6.4 and later ec2-user
RHEL 6.3 and earlier root
Fedora ec2-user
Centos root

月亮是我掰弯的 2024-08-12 12:22:36

只是添加到这个列表中。今天早上,我在刚刚添加到 AWS EC2 实例的新用户时遇到了问题。言归正传,问题出在 selinux (处于强制模式),而且我的用户主目录位于新的 EBS 附加卷上。不知何故,我猜 selinux 不喜欢其他卷。我花了一段时间才弄清楚,因为我查看了所有其他常见的 ssh 问题(/etc/ssh/sshd_config 很好,当然不允许密码,权限正确,等等)

修复?

现在(直到我了解如何允许用户 ssh 到不同的卷,或者以某种方式使该卷成为真正的主目录点):

sudo perl -pi -e 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
sudo setenforce 0

就是这样。现在我的新用户可以使用他自己的 id_rsa 密钥登录。

Just adding to this list. I was having trouble this morning with a new user just added to an AWS EC2 instance. To cut to the chase, the problem was selinux (which was in enforcing mode), together with the fact that my user home dir was on a new EBS attached volume. Somehow I guess selinux doesn't like that other volume. Took me a while to figure out, as I looked through all the other usual ssh issues (/etc/ssh/sshd_config was fine, of course no password allowed, permissions were right, etc.)

The fix?

For now (until I understand how to allow a user to ssh to a different volume, or somehow make that volume a bona fide home dir point):

sudo perl -pi -e 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
sudo setenforce 0

That's it. Now my new user can log in, using his own id_rsa key.

赤濁 2024-08-12 12:22:36

有同样的问题。尝试使用“ec2-user”或“root”登录时权限被拒绝(公钥)。

在 Google 上搜索了机器映像的 AMI 编号,它在 Debian wiki 页面上有 SSH 登录信息。

希望这有帮助。

Had the same issue. Permission denied (publickey) when trying to login in with 'ec2-user' or with 'root'.

Googled the AMI number of the machine image and it had the SSH login information right their on the Debian wiki page.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文