Permission denied (publickey)

After downloading aws-alias.sh, and running aws-start, everything works fine, and my instance begins running. However, when I go to run aws-ssh, I get these errors. I tried both the aliased command of aws-ssh and the direct ssh ubuntu@$instanceIp command, and both give me the following error of permission denied(public key).

    $ aws-ssh
    Warning: Identity file /home/xxxx/.ssh/aws-key.pem not accessible: No such file or directory.
    Permission denied (publickey).

    $ ssh ubuntu@$instanceIp
    Permission denied (publickey).

If anyone has any idea on what to do it would be greatly appreciated. I checked several websites and the aws documentation for the error and they do not seem to work. Thank you!

1 Like

in the new aws, the name of the key file changed ā€œaws-key-fast-ai.pemā€ ā€“ check yours though, donā€™t know if itā€™s been updated

(ps with questions like these, check/post on the aws setup forum!)

2 Likes

Thanks for the response, and Iā€™ll be sure to do that if I have any more questions regarding setup. I checked the key file and I had downloaded the old aws-alias file, and just redownloaded the newer version from github. Thank you for the clarification.

Hi Iā€™m having the same problem - how did you redownload the newer version?
(iā€™m a beginner). Did you have to re-install everything from scratch or is there a quick fix?
I was having trouble using wget with github filesā€¦ kept giving me an error.

Hi. I am having the same problem. Not sure what to do. I am using the new name aws-key-fast-ai.pem. It seems correct to me. It is really discouraging to get aws setup. Any help is appreciated.

I have same problemā€¦

I was able to resolve this.

let me rephrase the problem first, as directed, i would create and launch a EC2 instance and eventually the jupyter Notebook and do all the work and the end of session stop the instance.

next day while starting again, i would try to start the instance (which would start with aws-start and the steps before) but it would connect to the instance with above error!.

ok, here is what i checked:

the keypair name in my Amazon console is aws-key

and then i run the command (instance is already running, as can be seen via web console) :

$ ssh -i ā€œ~/.ssh/aws-key.pemā€ ubuntu@$instanceIp

and violaā€¦ its running again.

after several days of frustration now i can work, save and then start again from there.

cheers

1 Like

Also having the same problem. I tried re-create the key from aws, or using bash to create the key. But still cannot login with ssh. Always with Permission Denied(Public Key).

Here is my log info:

debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:4a74I7z22EOwAvO8RByupKwLyptWrbzsXY+iTpYXxUk
debug3: hostkeys_foreach: reading file "/home/husidi/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/husidi/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from ec2-35-163-207-144.us-west-2.compute.amazonaws.com
debug3: hostkeys_foreach: reading file "/home/husidi/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/husidi/.ssh/known_hosts:3
debug3: load_hostkeys: loaded 1 keys from 35.163.207.144
debug1: Host ā€˜ec2-35-163-207-144.us-west-2.compute.amazonaws.comā€™ is known and matches the ECDSA host key.
debug1: Found key in /home/husidi/.ssh/known_hosts:4
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug2: key: /home/husidi/.ssh/id_rsa (0x0)
debug2: key: /home/husidi/.ssh/id_dsa (0x0)
debug2: key: /home/husidi/.ssh/id_ecdsa (0x0)
debug2: key: /home/husidi/.ssh/id_ed25519 (0x0)
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/husidi/.ssh/id_rsa
debug3: no such identity: /home/husidi/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/husidi/.ssh/id_dsa
debug3: no such identity: /home/husidi/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/husidi/.ssh/id_ecdsa
debug3: no such identity: /home/husidi/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/husidi/.ssh/id_ed25519
debug3: no such identity: /home/husidi/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
ubuntu@ec2-35-163-207-144.us-west-2.compute.amazonaws.com: Permission denied (publickey).

Iā€™m having the Permission denied (publickey) problem also.

I checked the key pair per @tahirā€™s suggestion and thatā€™s not it.

@huxhu can you share how you created that log info?
I will go look for an ssh verbose option to create something similar (in case thatā€™s how you did it.)

Hi,

You can use ā€œ-vvvā€ to print the message, like ssh -vvv -i (your login command)

Actually I found once we lost the key there is no way to re-create as the key is generated when the instance was created. To solve the problem you have to create another instance to connect to the old one. you can refer to (https://forums.aws.amazon.com/message.jspa?messageID=475034)