Can you move the .pem key to a different directory or will that affect your ability to ssh (provided you use the correct path when you ssh)?

Viewed 69

I'm getting the following error when I try to ssh.

ssh -i "my-key.pem" ec2-user@ec2-x-xx-xxx-xxx.compute-1.amazonaws.com
The authenticity of host 'ec2-x-xx-xxx-xxx.compute-1.amazonaws.com (x-xx-xxx-xxx)' can't be established.
ECDSA key fingerprint is XXXXX.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ec2-x-xx-xxx-xxx.compute-1.amazonaws.com,x-xx-xxx-xxx' (ECDSA) to the list of known hosts.

Will that still occur if I move the key?

2 Answers

No, that is not an error. That is a warning that SSH issues because it is not sure that the machine you are trying to connect is actually the one you want to. You are supposed to check that the fingerprint shown there matches the one you see on your Amazon EC2 Console. As VonC said in their answer, once the ~/.ssh/known_hosts is updated, reflecting that you know and trust this machine, you won't see this warning, even if you move your key and reference it correctly.

You will only see a warning related to this if the fingerprint associated to the machine changes

First, this is not an error, only a way to update ~/.ssh/known_hosts at the first connection.

Second, you can move your key anywhere, as long as you reference it:

  • either with ssh: ssh -i "/new/path/to/key"
  • or with a ~/.ssh/config file

The second one would be:

Host ec2
   Hostname ec2-x-xx-xxx-xxx.compute-1.amazonaws.com
   User ec2-user
   IdentityFile /new/path/to/key

A simple ssh ec2 will reference the new key path.

Related