How to connect to an EC2 instance with non ec2-user
By default the AWS EC2 instance come with the ec2-user access enabled via access keys. If we choose to keep the key access only and try to create other users that require access to the host we need to make some changes.
Error Message :
Please login as the ec2-user user rather than “user X ” user.
Before we go into more details i assume you have a user on the EC2 instance you wanna connect, can be root or any new user.
You need to create the folder .ssh in the new user home and do the following steps:
cp /home/ec2-user/.ssh/authorized_keys home/<user>/.ssh/
chmod 700 /home/<user>/.ssh
chmod 600 /home/<user>/.ssh/authorized_keys
chown -R <user>:<usergrp> /home/<user>/
Next you need to create private key using the public key you were using to log in as ec2-user.
Follow the steps bellow:
1 – Open the putty Key Generator :
4 – Open a new putty session and type the ipaddress of the ec2 instance:
Go to SSH -> Auth, and paste the full patf to the new generated key.
Now you should be good to go and connect to the ec2 instance using the key and any other user you choose.