Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple keys for elastic beanstalk instance?

There is a very good question on [How to] SSH to Elastic [an] Beanstalk instance, but one thing I noticed is that, through this method, it is only possible to add one SSH key.

How can I add multiple SSH keys to an instance? Is there a way to automatically add multiple keys to new instances?

like image 805
NT3RP Avatar asked Nov 02 '12 18:11

NT3RP


People also ask

How do I add a key to an instance?

To add or replace a key pairConnect to your instance using your existing private key. Using a text editor of your choice, open the . ssh/authorized_keys file on the instance. Paste the public key information from your new key pair underneath the existing public key information.

How do I add a key pair to an EC2 instance?

Create a key-value pair from EC2 -> Key Pairs (Under NETWORK & SECURITY tab) Go to Elasticbeanstalk and click on your application. Go to configuration page and modify security settings. Choose your EC2 key pair and click Apply.

Can we use same key pairs with multiple instances?

Bottom line: You can use the same keypair on multiple instances and you can also use multiple keypairs on the same user on an instance. Show activity on this post. Yes, you can use one key pair for multiple EC2 instances. Click the "Launch" button and click "Choose an existing key pair."


2 Answers

To create a file named .ebextensions/authorized_keys.config is another way to do it.

files:   /home/ec2-user/.ssh/authorized_keys:     mode: "000400"     owner: ec2-user     group: ec2-user     content: |       ssh-rsa AAAB3N...QcGskx keyname       ssh-rsa BBRdt5...LguTtp another-key 

The name of file authorized_keys.config is arbitrary.

like image 110
rch850 Avatar answered Oct 04 '22 11:10

rch850


Combining rhunwicks's and rch850's answers, here's a clean way to add additional SSH keys, while preserving the one set through the AWS console:

files:   /home/ec2-user/.ssh/extra_authorized_keys:     mode: "000400"     owner: ec2-user     group: ec2-user     content: |       ssh-rsa AAAB3N...QcGskx keyname       ssh-rsa BBRdt5...LguTtp another-key commands:   01_append_keys:     cwd: /home/ec2-user/.ssh/     command: sort -u extra_authorized_keys authorized_keys -o authorized_keys   99_rm_extra_keys:     cwd: /home/ec2-user/.ssh/     command: rm extra_authorized_keys 

Note that eb ssh will work only if the private key file has the same name as the private key defined in the AWS console.

like image 23
scribu Avatar answered Oct 04 '22 10:10

scribu