简体   繁体   中英

“Permission denied (publickey).” while trying to SSH into Amazon EC2

I have an iPython installation on AWS, which I can access via the browser just fine. When I try to ssh to the EC2 instance though, I get the following error:

Permission denied (publickey).

I have tried using my existing .pem key, as well by generating new keys, nothing has worked still. These are the steps I have followed:

  1. $ chmod 700 ~/.ssh
  2. cp ~/desktop/aws/ipython.pem ~/.ssh/ipython.pem
  3. chmod 600 ~/.ssh/ipython.pem
  4. ssh -i ~/.ssh/ipython.pem ubuntu@50.174.xx.xx

On running the ssh command "ssh -i ~/.ssh/ipython.pem ubuntu@50.174.xx.xx -v", I get the following response:

OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /Users/coffeeman/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 102: Applying options for *
debug1: Connecting to 50.174.xx.xx [50.174.xx.xx] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/coffeeman/.ssh/ipython.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/coffeeman/.ssh/ipython.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to 50.174.xx.xx:22 as 'ubuntu'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:uBRsbvwsIcqNN7vUfzpIXd6n7W5cpyGyU0DutxEHJE8E
debug1: Host '50.174.xx.xx' is known and matches the ECDSA host key.
debug1: Found key in /Users/coffeeman/.ssh/known_hosts:10
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/coffeeman/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/coffeeman/.ssh/ipython.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

What am I doing wrong?

It looks like you didn't use this key to create your EC2 instance. Here's how to do it

  • Go to the EC2 console
  • Click on Launch an instance , and choose your OS, instance type, etc.
  • You will get to this window

在此处输入图片说明

  • Select Create a new key pair from the option list and give it a name, for instance ipython
  • Click on Download keypair
  • Store this in ~/.ssh/ipython.pem
  • Connect to your instance via SSH using

    ssh -i ~/.ssh/ipython.pem your-ip

And everything should be fine! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM