I am doing a group project for a class and I am hosting the project on an EC2 AIM instance and have it so I can connect to it from the machine I made it on. I need to create 6 accounts for my group members to use to connect from their machines. If anyone could provide assistance I would greatly appreciate it!
If I want to use the same key for everyone will I have to supply them with the .pem file so they can add it to their local .ssh folder on their machines? I’m pretty new to dealing with servers and pretty much have no idea how to do this, so I really appreciate the help.
It’s a pretty bad idea for everyone to use the same key. Are they ssh’ing in from windows or linux?
If they’re connecting from linux, they should run ‘ssh-keygen’ on their local machines, then you should copy the contents of their local ~/.ssh/id_rsa.pub to your EC2 server /home/username/.ssh/authorized_keys file for each different user account.
They can even do this themselves automatically by typing “ssh-copy-id username@ip-of-ec2-server” then typing the password that you give them and it’ll copy the key into authorized_keys automatically for you.
and if you’re inexperienced enough to need to be told that, you probably also need to be told: use the public key, not the private key in the authorized_keys file
Have your members create their own key pairs - preferably password protected key pairs - using this command:
ssh-keygen -t rsa -b 8192
Have them give you their public keys. They should never give you their private keys and/or passphrase.
When you launch an AWS Linux AMI you can use the following script in the User Data field to automatically add the members and disable login. The snippet below shows how to do it for two users - simply add as many members as you need and paste in their public keys:
Once the instance is launched and assuming that you have your security groups configured correctly they should be able to login to the instance using their username and key pair.
This will update the packages (apt-get update && apt-get upgrade on debian based machines) and provision the users with keys.
Once the instance is booted the users will be able to login using ssh.
I’ve just dealt with this today for a proof of concept. The trouble with userdata is it is intransigent. To update the users you need to update your launch configuration and recycle the instance.
What I have done for a proof of concept environment that doesn’t yet need CI tooling or central management is have the userdata install git and ansible, then clone a repo with users and ssh keys in a common role, and then apply the playbook locally. The playbook can then be run on demand, automatically or by a hook to update users without cycling the instance.
Ya, but in this case this wasn’t needed in this case.
I’m using Cloudinit to provision the ansible user + key (and some other minor stuff). After cloudinit is complete we use the Phone home (http://cloudinit.readthedocs.io/en/latest/topics/examples.html#call-a-url-when-finished) to call our Ansible master. That one will then push the correct playbook (with all user provisioning included) to the new box.
If someone leaves, we can update our ansible playbook and push the new changes to all boxes.
I’m interested in your POC, do you use ansible-pull to do this the normal ansible way but against the localhost?