Skip to content

Instantly share code, notes, and snippets.

@nawazm92
Last active December 18, 2019 12:44
Show Gist options
  • Save nawazm92/1dd6d42d5c07436d50a586fb76eb31b1 to your computer and use it in GitHub Desktop.
Save nawazm92/1dd6d42d5c07436d50a586fb76eb31b1 to your computer and use it in GitHub Desktop.
Add new user accounts with SSH access to Amazon EC2 Linux (Ubuntu) instance
  1. Create a key pair for the new user account
  2. Connect with root into SSH
  3. Run following commands
  • $ sudo adduser deployer OR sudo adduser new_user --disabled-password (without password)
  • $ sudo su - new_user
  • $ mkdir .ssh
  • $ chmod 700 .ssh
  • $ touch .ssh/authorized_keys
  • $ chmod 600 .ssh/authorized_keys
  1. [IN LOCAL SYSTEM] Retriev the Public Key for the Key Pair we just created in STEP-1, command below
  • $ ssh-keygen -y -f /path_to_key_pair/my-key-pair.pem

  • If the command fails, ensure that you've changed the permissions on your key pair file so that only you can view it by running the following command: $ chmod 400 my-key-pair.pem

  • and then do ssh-keygen command again

  1. cat >> .ssh/authorized_keys
  2. Paste the public key into the .ssh/authorized_keys file and then press Enter
  3. Ctrl + d to finish

Finally, Verify that you can connect to your EC2 instance using ssh as the new_user by running the following command from a command line prompt on your local computer $ ssh -i /path/new_key_pair.pem new_user@public_dns_name_of_EC2_Linux_instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment