I am trying to connect to my EC2 instance via the Terminal on Mac. My key is stored in /downloads folder and I have already ran the following command :
chmod 600 mykey.pem
before running the following :
ssh -t mykey.pem root@public-ip4-address
I have tried other usernames also - "ec2-user", "root", "admin" etc. But nothing seems to work.
hostkeys_find_by_key_hostfile: hostkeys_foreach failed for /Users/abhisheksharma/.ssh/known_hosts: Not a directory
The authenticity of host 'xxxxxxxxxxxxxxxxx' can't be established.
ED25519 key fingerprint is SHA256:Uw1xxxxxxxxxxxxxxxxxxxxxSIb57A.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/Users/abhisheksharma/.ssh/known_hosts).
root@xxxxxxxxxxxxx: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
More Details :
abhisheksharma@Abhisheks-MacBook-Air downloads % ssh -i storme.pem [email protected] -v
OpenSSH_8.6p1, LibreSSL 3.3.6
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 xxxxxxxxxxxxxxxx.compute.amazonaws.com port 22.
debug1: Connection established.
debug1: identity file storme.pem type -1
debug1: identity file storme.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to xxxxxxxxxxxxxxxxcompute.amazonaws.com:22 as 'root'
debug1: load_hostkeys: fopen /Users/abhisheksharma/.ssh/known_hosts: Not a directory
debug1: load_hostkeys: fopen /Users/abhisheksharma/.ssh/known_hosts2: Not a 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: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-xxxxxxxx SHA256:Uw1ljnksxxxxxxxxxxxxxxxxSIb57A
debug1: load_hostkeys: fopen /Users/abhisheksharma/.ssh/known_hosts: Not a directory
debug1: load_hostkeys: fopen /Users/abhisheksharma/.ssh/known_hosts2: Not a 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
hostkeys_find_by_key_hostfile: hostkeys_foreach failed for /Users/abhisheksharma/.ssh/known_hosts: Not a directory
The authenticity of host 'ec2-xxxxxxxxxxxxxxxx.compute.amazonaws.com (xxxxxxxxxxxxxxxx)' can't be established.
ED25519 key fingerprint is SHA256:Uw1ljnkxxxxxxxxxxxxxxxxIb57A.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/Users/abhisheksharma/.ssh/known_hosts).
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: storme.pem explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: publickey
debug1: Trying private key: storme.pem
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
CodePudding user response:
Use like this
ssh -i Downloads/<pemfile>.pem ubuntu@<publicip>
if created machine is of ubuntu
CodePudding user response:
Try this :
chmod 400 mykey.pem
Instead of
chmod 600 mykey.pem
and instead of root try adding ec2-user
It worked for me!