Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSHing into EC2 server via gives error Please login as the ec2-user user rather than root user

Tags:

ssh

amazon-ec2

Question as title. Why is this, I have used the ssh command: ssh -i mykey.pem [email protected] But i get that error, find nothing on google. What am I doing wrong?

like image 310
Tom Avatar asked Nov 20 '10 00:11

Tom


People also ask

Why can I not connect to my EC2 instance?

Verify that your instance is ready Check your instance to make sure it is running and has passed its status checks. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances, and then select your instance.

How do I connect to Amazon EC2 via SSH?

To connect from the Amazon EC2 consoleOpen the Amazon EC2 console. In the left navigation pane, choose Instances and select the instance to which to connect. Choose Connect. On the Connect To Your Instance page, choose EC2 Instance Connect (browser-based SSH connection), Connect.


2 Answers

You log in as ec2-user as Klaus suggested:

ssh -i key.pem ec2-user@host 

... and then you use sudo to run commands. E.g., to edit the /etc/hosts file which is owned by root and requires root privileges: sudo nano /etc/hosts.

Or you run sudo su to become the root user.

like image 193
Till Avatar answered Sep 22 '22 23:09

Till


By default root user is not allowed to login but you can use ec2-user as indicated by others.

Once you login with ec2-user you switch to root and change the SSH configuration.

To become the root user you run:

sudo su - 

Edit the SSH daemon configuration file /etc/ssh/sshd_config, e.g. by using vi, and replace the PermitRootLogin entry with the following:

PermitRootLogin without-password 

Reload the SSH daemon configuration by running:

/etc/init.d/sshd reload 

The message Please login as the ec2-user user rather than root user. is displayed because a command is executed when you login with the private key. To remove that command edit ~/.ssh/authorized_keys file and remove the command option. The line should start with the key type (Eg. ssh-rsa).

(*) Do at your own risk. I recommend you to leave always a console open just in case you're not able to login after you make the configuration changes.

For reference you can read the man pages:

man sshd_config man sshd 
like image 39
Juan Hernandez Avatar answered Sep 23 '22 23:09

Juan Hernandez