ssh-copy-id doesn't work with .pem files
Solution 1:
You can use ssh-copy-id
together with ssh-agent
. Load the my-new-key.pem
file to your agent using ssh-add ~/.ssh/my-new-key.pem
and then ssh-copy-id
will copy it to the new instance.
Alternatively you can run a new ssh-agent
for a better control of what's going to be copied:
~ $ ssh-agent bash -c "ssh-add ~/.ssh/my-new-key.pem; ssh-copy-id -i already-on-remote-server-key.pem user@host"
One unsolicited advice - you can reuse the EC2 keys across all AWS regions to reduce the number of keys you need to generate and maintain: Re-using EC2 Key Pair in multiple regions.
Hope that helps :)