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?
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.
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.
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."
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With