11

I need to send a public key to an EC2, without use the ec2-* api commands, and I can't.

I've tried scp and ssh-copy-id, but booth can't use the -i parameter to connect using the keypairs.

The ssh-copy-id -i parameter are the file (public key) to be sent.

What can I do to upload it?

TiagoGouvea
  • 341
  • 1
  • 2
  • 6
  • scp does support -i. What command did you try to run and what's the output? – dfranke Nov 15 '10 at 03:46
  • I'm also not clear on exactly what you're trying to do. Are you trying to launch an instance with an ssh key that you generated locally, or do you have an already-running instance that you're trying to install a second key onto? – dfranke Nov 15 '10 at 03:47
  • dfranke. I can connect to the instance at this time, using ssh -i file.pem. But I need make a cron in the client side with rsync, then, I need to have acess withou autentication. – TiagoGouvea Nov 15 '10 at 12:32
  • I create the public keys in the client side but I can't send it to server. It's the only problem. How to send my public keys from client to server. :( I think it's simple, but at this time I can't. – TiagoGouvea Nov 15 '10 at 12:34
  • @TiagoGouvea `scp` does support `-i`. You can use it as `scp -i your_pem.pem your_file user@aws_ip:/home/user/`. You probably be getting error because of your permissions on your pem file. It should be `400` (i.e. `chmod 400 your_pem.pem`) – guleria Feb 17 '16 at 07:38

1 Answers1

13

Ok! I found an way.

In the client side:

cat ~/.ssh/id_rsa.pub | ssh -i aws.pem ubuntu@ip_address "cat - >> ~/.ssh/authorized_keys2"

All done!

TiagoGouvea
  • 341
  • 1
  • 2
  • 6
  • What is the actual problem you're trying to solve that leads you to thinking this is the way to solve it? – bobmagoo May 22 '14 at 15:00
  • The problem this solved for me is wanting a one-liner to get my local pub key into a newly setup EC2 instance's `authorized_keys`. Avoids doing an scp then logging in via pem and putting it in the right place. – ljs.dev Jul 23 '17 at 05:50
  • Looks like `authorized_keys2` is deprecated, `authorized_keys` should be used (see [here](https://serverfault.com/questions/116177/whats-the-difference-between-authorized-keys-and-authorized-keys2)) – Nero Vanbiervliet Nov 24 '21 at 11:11