-2

I am getting Permission denied (publickey) error while copying a public key using this command over ec2 ubuntu instance

root@ip-172-31-5-68:~# ssh-copy-id docadmin@ip-172-31-13-212

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:"/root/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

docadmin@ip-172-31-13-212: Permission denied (publickey).

Can anyone help me why I am getting this permission issue?

jww
  • 97,681
  • 90
  • 411
  • 885
SANDEEP
  • 1,062
  • 3
  • 14
  • 32

1 Answers1

-1

AWS doesn't allow SSH connections to an EC2 instance with private keys that are publicly exposed.

While you're trying to copy a .pub (public key) over to instance 2, you're using ssh-copy-id, which uses ssh under the hood to facilitate the transfer, so you'll first need to lock down your private key on instance 1.

Substituting the last term for your private key .pem filepath, you can accomplish this with:

chmod 400 /path/to/your-private-key.pem


The following post seems to be the canonical reference for this topic, but this is a slightly different scenario, so I'm not going to mark it as a duplicate:

Nick Walsh
  • 1,807
  • 5
  • 16