Skip to content

Instantly share code, notes, and snippets.

@eynopv
Created September 16, 2022 07:27
Show Gist options
  • Save eynopv/584662472804ad8271fd4c8f520f47ed to your computer and use it in GitHub Desktop.
Save eynopv/584662472804ad8271fd4c8f520f47ed to your computer and use it in GitHub Desktop.

How to add new user to AWS ec2 instance?

  1. Login as a ec2-user to the instance
$ ssh -i ~/.ssh/<key> ec2-user@<ip-address>
  1. Create user
$ sudo useradd newuser
  1. Allow ssh access for the user

Login as new user

$ sudo -su newuser

Create ssh directory

$ cd /home/newuser
$ mkdir .ssh
$ chmod 700 .ssh
$ cd .ssh

Add ssh key

$ touch authorized_keys
$ chmod 600 authorized_keys
$ echo "<public_key>" > authorized_keys
  1. Validate access
$ ssh -i ~/.ssh/newuser-private-key newuser@<ip-address>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment