Set a new user with password login on AWS EC2 linux Instance
Creating a new user on EC2 instance and access it remotely via ssh.
Filter by Category
Filter by Author
Login to your elastic compute instance with a private-key each time isn’t quite convenient. So we will change that by creating a new user, set ssh config and enabling password login at our EC2 instance.
First, login into ( SSH ) your EC2 instance with default username which is ec2-user using your private-key file that has the extension (.pem)
# follow the following pattern replace with your own private key and DNS
# ssh -i "./my-private-key.pem" ec2-user@<YOUR_PUBLIC_DNS>
ssh -i "./my-private-key.pem" firstname.lastname@example.org
know we’ve access to our EC2 instance let’s create a new user and call him joe.
# create new user joe
$ sudo useradd -c "joe" -m joe
# set the password
$ echo "pass12345" | sudo passwd --stdin joe
# grant him a sudo privilege by assign it to the root group
$ sudo usermod -aG wheel joe
# switch to joe account
$ su - joe
Configure ssh for the new user account
# make sure you are in the joe directory I.E /home/joe
# create a .ssh directory in the joe home directory
$ mkdir .ssh
# set the correct permission at .shh directory
$ chmod 700 .ssh
store our public-key inside .ssh directory
#create file inside .ssh directory to store the public key
$ touch .ssh/authorized_keys
# set user read/write permission at authorized_keys file
$ chmod 600 .ssh/authorized_keys
Now we added a new user to EC2 instance. let’s jump back to our local machine to retrieve the public-key from the private-key file (my-private-key.pem).
using Linux/MacOs fire ? up the terminal and type
$ ssh-keygen -y -f /path_to_key_pair/my-key-pair.pem
# I.E result
For windows users
Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key
Great! ? now we attained the public-key. We can ssh back to the EC2 instance and switch to Joe account. Navigate to /home/joe directory and copy the public-key to the .ssh/authorized_keys file. But, before editing the file using vim, just make sure you know how to exit :wq! ?
# In the directory /home/joe
$ vim .ssh/authorized_keys
One last step remain, Changing the config file allowing password login. so we edit
sshd_config and set PasswordAuthentication yes.
# open sshd_config then set PasswordAuthentication yes
$ vim /etc/ssh/sshd_config
$ sudo service sshd restart
Exit the SSH and then login to test the password authentication.
So this article is about validating a fun logic game called sudoku. Sudoku board is consists of 9×9 gird, which contains 3×3 subgrids.The objective is to fill a 9×9 grid...