开发者

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

Question as title. Why is this, I have used the ss开发者_开发知识库h command: ssh -i mykey.pem root@xxx-xxx-xx-xx-xxx.compute-1.amazonaws.com But i get that error, find nothing on google. What am I doing wrong?


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.


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


I have encountered a similar problem when setting up a hadoop cluster on Amazon ec2.

My head node needs to have root ssh access to each worker/slave nodes. I aliased the connects by adding each slave node's IP address, private address, and alias name to the /etc/hosts/ file. (I get that data by running the command echo -e "`hostname -i`\t`hostname -f`\talias-name" where alias-name is what I call each node (head or n1 for example). Then I put that output for each node in every node's /etc/hosts file.

The problem I have been encountering is that when I type ssh n1 while in my head node to ssh into my first slave node, I get that same error message: Please login as the use "ec2-user" rather than the user "root". So after doing some research, I figured out how to fix it.

First:

  • ssh into your server. non-root (ec2-user) access is fine here.
  • Then su - your way into root. Now vi /etc/ssh/sshd_config and un-comment the line PermitRootLogin yes.
  • Exit vi editor.
  • Now restart ssh daemon by typing service sshd stop then service sshd start.

Second:

  • Now, here is the part I had to dig for,
  • run vi /root/.ssh/authorized_keys
  • Comment out everything up to ssh-rsa. Just put a # at the beginning of the file's content, before no-port-forwarding... and hit enter on ssh-rsa to move it to the next line (this way you dont have to delete anything in case you want to backtrack).
  • exit vi editor

Now you should be able to login to root without that error message popping up.

Also, if you are using aliases for a cluster setup; Repeat the same steps on each node. First ssh in using ec2-user then follow the steps. After adding the IP address, private address, and alias name info to your /etc/hosts file you should be able to ssh into each node's root using the alias name for example ssh n1.

The tutorial I followed is here: https://www.youtube.com/watch?v=xrxQXfE7t9A

But it didnt discuss the problem with root login.

Hope that helps! It worked for me.

*Keep in mind that I havnt taken any security into concern. This is simply a practice/dev setup.


I think it's just asking you to login with another username. Do you happen to have a user called ec2-user? If so, try this instead:

ssh -i mykey.pem ec2-user@xxx-xxx-xx-xx-xxx.compute-1.amazonaws.com


I have faced the same problem when I tried to access my EC2 instance as 'root' through Windows PuTTY client, this is how I solved problem.

  1. Access and edit SSH configuration file, to allow root login and password authentication.

    • Login as ec2-user (by default it is allowed)
    • Enter below command to open ssh config

      sudo vi /etc/ssh/sshd_config

    • Edit SSH configuration file as below using vi, how to use vi editor

      PermitRootLogin yes (remove # at begging if it present)

      PasswordAuthentication yes

  2. Restart SSH

    sudo /etc/init.d/sshd restart

  3. Change/set root password

    sudo passwd root

    type new password and re-enter it (at least 8 characters)

  4. Exit current session and close PuTTY

    exit

  5. Try again login as root and type previously set password.


Solved! Try compare root key file and user key file)

diff /root/.ssh/authorized_keys /home/user/.ssh/authorized_keys

...and see


For anyone like me that created a new user, copied root's .ssh dir to the new user, set ownership and STILL got this error - look at the new user's ~/.ssh/authorized_keys file. It has SSH params specified that force the prompt. Delete everything from that line up to the ssh-rsa and you'll be good to go.

Or - copy /home/ec2-user/.ssh to the new user homedir instead of /root/.ssh


Edit /etc/ssh/sshd_config, and make sure this is set:

PasswordAuthentication yes

Then reload SSH:

systemctl reload sshd.service

You can now log in as users other than ec2-user.


ssh -i mykey.pem root@xxx-xxx-xx-xx-xxx.compute-1.amazonaws.com

just replace above command to this

ssh -i mykey.pem ubuntu@xxx-xxx-xx-xx-xxx.compute-1.amazonaws.com

its working in my case


For those who are looking for a single, simple line:

sudo ssh -i ./mykey.pem ec2-user@ec2-x-xx-xxx-xxx.us-east-2.compute.amazonaws.com

Note that, you can get the line after the @ from the Public IPv4 DNS section in your instance summary page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜