When an Ubuntu EC2 instances is created in the AWS Cloud, we should be able to connect to the EC2 using the username/password and the Keypairs. In the case of the Ubuntu AMI provided by AWS, only the Keypair authentication is enabled while the username/password authentication is disabled. Very often I get the query "How to create additional users for the Ubuntu EC2 with Keypair for authentication", so is the blog. At the end of the day, Linux is a Linux weather we run it in the Cloud, Laptop or in On-Premise, so the instructions apply everywhere.
Setting up an EC2 user with username/password authentication
Step 1: Create an Ubuntu EC2 instance and connect to it
Step 2: Add user "praveen" using the below command
#Enter the password and other details
sudo adduser praveen
Step 3: Open the "/etc/ssh/sshd_config" file and set "PasswordAuthentication" to yes
Step 4: Restart the ssh service
sudo service ssh restart
Step 5: Connect to the EC2 as the user "praveen" via Putty or some other software by specifying the password
Setting up an EC2 user with Keypair authentication
Step 1: Add user "sripati" and disable the the password authentication
#as we would be using the Keypair for authentication
sudo adduser sripati --disabled-password
Step 2: Switch as the user
sudo su - sripati
Step 3: Generate the keys. They would be in the .ssh folder
ssh-keygen
Step 4: Copy the public key to the authorized_keys file in the .ssh folder
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
Step 5: Copy the private key in the ~/.ssh/id_rsa to a file sripati.pem on your local machine
cat ~/.ssh/id_rsa
Step 6: Using PuttyGen convert the pem file to ppk. "Load" the pem file and "Save private key" in the ppk format.
Step 7: Now connect via Putty via the username as "sripati", the public IP of the EC2 instance and private key in the ppk format. There is no need to specify the password.
No comments:
Post a Comment