I have been stuck while connecting ubuntu instance with ssh. I have created three instance of ubuntu on aws using ansible agent. From that local ubuntu computer from which I created instance , I am able to ssh but from other computers , I couldnt been able to connect it.I tried almost all threads and available solution on aws and stackoverflow but still I am unable to solve this.Following are the steps I have done.
1- Download private key .
2- chmod 600 private key.
3- ssh -vvv -i ~/.ssh/sshkeys.pem[email protected]
Here is the output of this command
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /etc/ssh/ssh_config line 19: Applying options for *debug2: resolving "ec2-34-200-240-218.compute-1.amazonaws.com" port 22debug2: ssh_connect_direct: needpriv 0debug1: Connecting to ec2-34-200-240-218.compute-1.amazonaws.com [34.200.240.218] port 22.debug1: Connection established.debug1: key_load_public: No such file or directorydebug1: identity file /home/obaid/.ssh/sshkeys.pem type -1debug1: key_load_public: No such file or directorydebug1: identity file /home/obaid/.ssh/sshkeys.pem-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000debug2: fd 3 setting O_NONBLOCKdebug1: Authenticating to ec2-34-200-240-218.compute-1.amazonaws.com:22 as 'ubuntu'debug3: hostkeys_foreach: reading file "/home/obaid/.ssh/known_hosts"debug3: record_hostkey: found key type ECDSA in file /home/obaid/.ssh/known_hosts:1debug3: load_hostkeys: loaded 1 keys from ec2-34-200-240-218.compute-1.amazonaws.comdebug3: order_hostkeyalgs: prefer hostkeyalgs:[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521debug3: send packet: type 20debug1: SSH2_MSG_KEXINIT sentdebug3: receive packet: type 20debug1: SSH2_MSG_KEXINIT receiveddebug2: local client KEXINIT proposaldebug2: KEX algorithms:[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-cdebug2: host key algorithms:[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsadebug2: ciphers ctos:[email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbcdebug2: ciphers stoc:[email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbcdebug2: MACs ctos:[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1debug2: MACs stoc:[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1debug2: compression ctos: none,[email protected],zlibdebug2: compression stoc: none,[email protected],zlibdebug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug2: peer server KEXINIT proposaldebug2: KEX algorithms:[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519debug2: ciphers ctos:[email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]debug2: ciphers stoc:[email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]debug2: MACs ctos:[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1debug2: MACs stoc:[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1debug2: compression ctos: none,[email protected]debug2: compression stoc: none,[email protected]debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug1: kex: algorithm:[email protected]debug1: kex: host key algorithm: ecdsa-sha2-nistp256debug1: kex: server->client cipher:[email protected] MAC: <implicit> compression: nonedebug1: kex: client->server cipher:[email protected] MAC: <implicit> compression: nonedebug3: send packet: type 30debug1: expecting SSH2_MSG_KEX_ECDH_REPLYdebug3: receive packet: type 31debug1: Server host key: ecdsa-sha2-nistp256 SHA256:oUC/x2Sgi1gt2UECZxyslyUd9cjVd4WHcXl4Dc18KXYdebug3: hostkeys_foreach: reading file "/home/obaid/.ssh/known_hosts"debug3: record_hostkey: found key type ECDSA in file /home/obaid/.ssh/known_hosts:1debug3: load_hostkeys: loaded 1 keys from ec2-34-200-240-218.compute-1.amazonaws.comdebug3: hostkeys_foreach: reading file "/home/obaid/.ssh/known_hosts"debug3: record_hostkey: found key type ECDSA in file /home/obaid/.ssh/known_hosts:2debug3: load_hostkeys: loaded 1 keys from 34.200.240.218debug1: Host 'ec2-34-200-240-218.compute-1.amazonaws.com' is known and matches the ECDSA host key.debug1: Found key in /home/obaid/.ssh/known_hosts:1debug3: send packet: type 21debug2: set_newkeys: mode 1debug1: rekey after 134217728 blocksdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug3: receive packet: type 21debug2: set_newkeys: mode 0debug1: rekey after 134217728 blocksdebug1: SSH2_MSG_NEWKEYS receiveddebug2: key: /home/obaid/.ssh/sshkeys.pem ((nil)), explicitdebug3: send packet: type 5debug3: receive packet: type 7debug1: SSH2_MSG_EXT_INFO receiveddebug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>debug3: receive packet: type 6debug2: service_accept: ssh-userauthdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug3: send packet: type 50debug3: receive packet: type 51debug1: Authentications that can continue: publickeydebug3: start over, passed a different list publickeydebug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,passworddebug3: authmethod_lookup publickeydebug3: remaining preferred: keyboard-interactive,passworddebug3: authmethod_is_enabled publickeydebug1: Next authentication method: publickeydebug1: Trying private key: /home/obaid/.ssh/sshkeys.pemdebug3: sign_and_send_pubkey: RSA SHA256:0qWOo8gOlfKj+hJG8fyN46rN+Gt0VQFauFhOen3p9kcdebug3: send packet: type 50debug2: we sent a publickey packet, wait for replydebug3: receive packet: type 51debug1: Authentications that can continue: publickeydebug2: we did not send a packet, disable methoddebug1: No more authentication methods to try.Permission denied (publickey)I tried to connect with Putty on windows machine but got same error on windows machine as well
- Have you issued this command as
sudouser?Zak– Zak2017-11-04 18:31:01 +00:00CommentedNov 4, 2017 at 18:31 - Hey @Zak which command? ssh? I have tried ssh command with sudo user but still facing same problemmohammad obaid– mohammad obaid2017-11-05 06:39:02 +00:00CommentedNov 5, 2017 at 6:39
1 Answer1
To Access Command Line Interface (Windows)Reading Materials:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html
1) Open Putty
2) Sign in: Host Name: Your server IP, Navigate to Connection -> SSH -> Auth(For the Private key file for Authentication use the .ppk file), Hit open
3) For user sign in: ubuntu
EXTRA to use root user type “sudo -i”
Comments
Explore related questions
See similar questions with these tags.

