Give Access to EC2 Server without PEM FILE or IAM ROLE .
Jira Ticket :
AS an SRE you have been asked to give a developer or manager or a client EC2 access without creating IAM ROLE or with out sharing PEM file .
solution :
If a user wants to log on to a server rather than giving them our pem key, create a local user with their public key.Ask the user to generate public key and share it with you .
step1:
Ask the user to send their public key.
Step2:
log onto the server where you want to grant the user access.
step3:
Create a local Linux user on a server.
- sudo useradd -m <username>
- Change to the newly created folder :
- cd /home/<username>
- Create a .ssh folder
- sudo mkdir .ssh
- Create a file called authorized_keys which will contain their public key
- sudo touch auth_keys
- Edit the file
- sudo vi auth_keys
- Now paste in the public key, make sure all of the file copies across.
- Exit the file
- Locked down permission to auth_keys
- chmod 400 auth_keys
- Go back a directory, to the users home
- cd ..
- Set the owner of the .ssh folder and contents to the user.
- sudo chown -R <username>:<username> .ssh
- Set the password for the user
- sudo passwd <username>
You will be prompted to enter a password. Make a note of this and send in a secure way to the user like pwpush.com.
- If the user needs to have admin rights to the server you can add them to the sudo group.
- sudo usermod -aG sudo <username>
- Contact the user saying the account has been created and what his sudo password is.
- For a user to connect to the EC2 they will need to point to their private key in the ssh connection string.
- ssh -i /path/to/private_key.pem username@priv_ip_address
Once the user has finished needing access to the remove their account