Permission denied (publickey) - unexpected error

0

Hi,

The other day I tried to connect by ssh into a EC2 instance running ubuntu. I'm getting this error:

Permission denied (publickey)

the command I am running is:

ssh -i "path to pem" ip-address

When I didn't used to get this error. I have done:

Verified that the correct private key is being used for SSH authentication. Confirmed that the instance is running and reachable. Checked the security group associated with the instance to ensure that inbound SSH traffic (port 22) is allowed from my IP address. Attempted to SSH from a different network to rule out local network issues. Reviewed system logs, but couldn't access them due to inability to SSH into the instance. I have confirmed that the instance is using the correct key pair. The instance is in a running state and hasn't been terminated.

  • Add -v and ensure that key is used.

  • OpenSSH_9.6p1, LibreSSL 3.3.6 debug1: Reading configuration data /Users/user/.ssh/config debug1: /Users/aj0312/.ssh/config line 1: Applying options for * debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files debug1: /etc/ssh/ssh_config line 54: Applying options for * debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling debug1: Connecting to ec2-18-135-142-222.eu-west-2.compute.amazonaws.com port 22. debug1: Connection established. debug1: identity file path/to/pem type -1 debug1: identity file path/to/pem-cert type -1 debug1: identity file path/.ssh/githubkey type 0 debug1: identity file path/.ssh/githubkey-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.6 debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.6 debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.6 pat OpenSSH* compat 0x04000000 debug1: Authenticating to ec2-18-135-142-222.eu-west-2.compute.amazonaws.com:22 as 'ubuntu' debug1: load_hostkeys: fopen /Users/aj0312/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: sntrup761x25519-sha51

  • The PEM file exists?

  • Please generate public key from private key and verify if it is match with server public key. ssh-keygen -f <path of pem file> -y. You can try to login through Systems Manager also. Nowadays some EC2 instances are coming with Systems Manager pre-installed.

  • The PEM file exists and I have double and triple checked it's path.

    How can I know if the EC2 instance has systems manager? I launched the instance a couple months ago

Alex J
asked a month ago227 views
1 Answer
3

Seems like you forget to provide the ubuntu username in your command. try:

ssh -i "path to pem" ubuntu@ip-address

AWS
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • Hi,

    Thanks for you answer. I removed the sensitive data from the command, this is what I used:

    ssh -i "~/path/to/pem" ubuntu@ec2----*.eu-west-2.compute.amazonaws.com

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions