I have been trying to connect to my EC2 all day, but keep getting error
Permission Denied (Publickey,Gssapi-Keyex,Gssapi-With-Mic)
So far I have done everything outlined in these articles, one from the AWS troubleshooting page to no avail.
This is the debug info I get when trying to connect:
➜ ~ ssh -vvv -i ~/path/to/pem/key.pem address.compute.amazonaws.com
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to address.compute.amazonaws.com port 22.
debug1: Connection established.
debug1: identity file /Users/kurt/path/to/pem/key.pem type -1
debug1: identity file /Users/kurt/path/to/pem/key.pem-cert type -1
.
.
.
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
kurt#address.compute.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Done in Terminal on OSX Catalina
https://phoenixnap.com/kb/ssh-permission-denied-publickey
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-fix-permission-denied-errors/
I made a new EC2 instance on AWS including a new key pair and adding SSH to the security group. Here's the output trace:
ssh.exe : OpenSSH_7.1p2, OpenSSL 1.0.2h 3 May 2016 At line:1 char:4
+ ssh <<<< -v -i .\CHEFtutorial.pem ec2-54-148-153-153.us-west-2.compute.amazo naws.com 2> out.txt
+ CategoryInfo : NotSpecified: (OpenSSH_7.1p2, ....2h 3 May 2016 :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to
ec2-54-148-153-153.us-west-2.compute.amazonaws.com [54.14
8.153.153] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file .\CHEFtutorial.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file .\CHEFtutorial.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version
OpenSSH_7.2p2 Ubun tu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat
0x04000000 debug1: Authenticating to
ec2-54-148-153-153.us-west-2.compute.amazonaws.com:22 as 'i861009'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305#openssh.com
none
debug1: kex: client->server chacha20-poly1305#openssh.com
none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256
SHA256:8jkpw+J1G8Lx8eamhiOYm0xTtCA
+ElsRgJznVyK7Rnw
debug1: Host 'ec2-54-148-153-153.us-west-2.compute.amazonaws.com' is
known and matches the ECDSA host key.
debug1: Found key in /c/Users/i861009/.ssh/known_hosts:2
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: Trying private
key: .\CHEFtutorial.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try. Permission denied
(publickey).
The input was ssh -v -i .\CHEFtutorial.pem ec2-54-148-153-153.us-west-2.compute.amazonaws.com. For what reason would the server be rejecting the key? I have not played with any permissions information, which other answers to this question have noted as an issue.
You have to also mention the name of the user you're doing ssh to on that server.
E.g. if the machine is an Ubuntu instance I'll have to do
ssh -v -i .\CHEFtutorial.pem ubuntu#ec2-54-148-153-153.us-west-2.compute.amazonaws.com
Try to find out the corresponding user for your machine. You can get it in AWS docs, I guess. Then just prefix username# before the server address.
Please make sure the permission of the pem file is 400
Go the Directory where pem file exist and execute
sudo chmod 400 CHEFtutorial.pem
then execute
ssh -v -i CHEFtutorial.pem username#ec2-54-148-153-153.us-west-2.compute.amazonaws.com
If it is an ubuntu servers provide username as ubuntu and for rhel or centos servers provide username as ec2-user.
Note:- if the owner of the pem file is root , provide the command with sudo
This answer is specifically designed for this type of question, but it has not yet been as clear to me as to its hundreds of upvoters.
I put my key in Downloads. It's found, but it seems like it's not considered a a public key when I use user ubunto. The output is at the bottom of this post. I changed permissions using sudo chmod 600 ~/downloads/mykey.pem but had the same result. I changed permissions using sudo chmod 700 ~/downloads/mykey.pem and had the same result too. From this answer, I tried sudo chown -R me ~/downloads/mykey.pem, then sudo chgrp -R 501 ~/downloads/mykey.pem where uid=501(me).
I have tried ec-2 and root as users without success.
with root as ec-2
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
with root as user
skipping output lines
debug1: Trying private key: /Users/me/downloads/mykey.pem
debug1: Authentication succeeded (publickey).
The authentication succeeds, but the connection closes.
skipping output lines
debug1: channel 0: free: port listener, nchannels 2
debug1: channel 1: free: port listener, nchannels 1
Connection to ec2-[myPublicIP].compute-1.amazonaws.com closed.
Transferred: sent 3264, received 2456 bytes, in 10.3 seconds
Bytes per second: sent 316.6, received 238.2
debug1: Exit status 0
Here is the output using user ubunto that the title of this question refers to:
ssh -v -i ~/downloads/mykey.pem -L 60051:localhost:60051 ubunto#ec2-[mypublicIP].compute-1.amazonaws.com
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to ec2[mypublicIP].compute-1.amazonaws.com [[mypublicIP]] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/me/downloads/mykey.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/me/downloads/mykey.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.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to ec2-[mypublicIP].compute-1.amazonaws.com:22 as 'ubunto'
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:85gcFh6LySYszjod4WIx5wu7BUvKwL4M6EAcZkv0zGw
debug1: Host 'ec2[mypublicIP].compute-1.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /Users/me/.ssh/known_hosts:11
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: Trying private key: /Users/me/downloads/mykey.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
What AMI are you using?
The default user in a stock Ubuntu AMI is ubuntu, not ubunto.
Unless you've created a special AMI that sets up an ubunto user, the user won't exist on the AMI, and hence fail to authenticate.
I read this post:
AWS ssh access 'Permission denied (publickey)' issue
The information there is relevant, but does not help me solve my issue. I used to be able to login to my linux instance on AWS using ec2-user using the following command:
ssh -i key.pem ec2-user#[address].compute-1.amazonaws.com from my MacBook terminal
over the past few weeks, I'm getting this error now:
"Permission denied (publickey)."
I tried
ssh -v -i key.pem ec2-user#[address].compute-1.amazonaws.com from my MacBook terminal
and I get this output:
OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to [address].compute-1.amazonaws.com [address] port 22.
debug1: Connection established.
debug1: identity file key.pem type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
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: Host '[address].compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in [path]/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
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: Trying private key: key.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
Any advice on what's going on? How to get around this?
I have another user account on this instance that I previously created. I am able to login with that, and sudo into the root. I just cannot login with ec2-user anymore.
Thanks!
You may have to log in as root. If using a bitnami image, login as 'bitnami'
e.g. ssh -v -i key.pem bitnami#[address].compute-1.amazonaws.com
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
How to connect to a AWS instance through ssh?
I have:
Signed up at AWS;
Created a public key and a certificate at AWS website and saved them to disk;
Went to my console and created environment variables:
$ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
$ export EC2_CERT=/home/default/aws/cert-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem
$ export EC2_PRIVATE_KEY=/home/default/aws/pk-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem
Told AWS API to use this keypair and saved the keypair to file:
$ ec2-add-keypair ec2-keypair > ec2-keypair.pem
Started an AWS Ubuntu 9 instance using this keypair:
$ ec2-run-instances ami-ed46a784 -k ec2-keypair
Attempted to establish a ssh connection to the instance:
$ ssh -v -i ec2-keypair.pem ubuntu#ec2-174-129-185-190.compute-1.amazonaws.com
OpenSSH_5.1p1 Debian-5ubuntu1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to ec2-174-129-185-190.compute-1.amazonaws.com [174.129.185.190] port 22.
debug1: Connection established.
debug1: identity file ec2-keypair.pem type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.1p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc 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: Host 'ec2-174-129-185-190.compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/default/.ssh/known_hosts:11
debug1: ssh_rsa_verify: signature correct
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: Trying private key: ec2-keypair.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
What could be the problem and how to make it work?
For Ubuntu instances:
chmod 600 ec2-keypair.pem
ssh -v -i ec2-keypair.pem ubuntu#ec2-174-129-185-190.compute-1.amazonaws.com
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
Now it's:
ssh -v -i ec2-keypair.pem ec2-user#[yourdnsaddress]
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.
If you're using a Bitnami image, log in as 'bitnami'.
Seems obvious, but something I overlooked.
For my ubuntu images, it is actually ubuntu user and NOT the ec2-user ;)
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 ec2-user#ec2-184-72-204-112.compute-1.amazonaws.com
above example was taken directly from the AWS tutorial for connecting to a Linux/UNIX machine at:
http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/
It will also complain if the pem file permissions are too open. chmod the file to 600 to fix that.
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!
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 root#54.254.250.***
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 no-more-sessions#openssh.com
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".
*
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
Use PuTTy to create the ssh session (http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.66-installer.exe)
If your private key file is in .pem format convert it into .ppk using puttygen
Launch PuTTy, set you ppk file, IP address or DNS name of the remote server and start the ssh session
use...
# chmod 400 ec2-keypair.pem
don't use the 600 permission otherwise you might overwrite your key accidently.
For Debian EC2 instances, the user is admin.
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 ec2-user#XX.XX.XX.XXX
Hope it helps !
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.
Permission for ec2-keypair.pem should be 400
chmod 400 ec2-keypair.pem
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
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)".
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
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.
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.