-1

I am trying to ssh into my ec2 instance from a centos 7 machine. I have added .pem file to .ssh folder.

Am i missing something?

[root@localhost .ssh]# cd /home/###/.ssh/
[root@localhost .ssh]# ls
##.pem

root@localhost .ssh]# ssh centos@10.100.140.52 -vvv


debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
user6826691
  • 1,813
  • 9
  • 37
  • 74

2 Answers2

1

You're the root user - it doesn't matter if you've got a pem file in the same directory, it's going to look in the default directory (/root/.ssh in your case). If you want to use that pem file, use the "-i" command line option:

ssh -i something.pem centos@10.100.140.52 -vvv
stdunbar
  • 16,263
  • 11
  • 31
  • 53
1

I see you are using a root shell, but your question states the key credentials are stored in a user's home directory. Does this work as that user, i.e.,

[root@localhost .ssh]# su - ###
[###@localhost ~]$ ssh centos@10.100.140.52 -vvv

You can also try to override where the ssh client is looking for .ssh files, although ssh gets picky about mismatched file permissions, i.e.,

[root@localhost ~]# ssh -i ~###/.ssh/something.pem centos@10.100.140.52 -vvv

You can store connection "profiles" in ~/.ssh/config, i.e.,

Host ec2
  HostName 10.100.140.52
  IdentityFile ~/.ssh/identity_file