添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
玩篮球的柠檬  ·  AudioFlinger could ...·  1 年前    · 
跑龙套的毛豆  ·  java ...·  1 年前    · 
含蓄的酸菜鱼  ·  vue-org-tree ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

Question as title. Why is this, I have used the ssh 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?

I was confused by the poorly-punctuated error message: I tried logging in as "user" rather than "ec2-user". Once I figured out that mistake, it worked fine. offby1 Mar 13, 2011 at 2:32 when i try to log in as ec2_user, it asks me for the passwd, which, of course, i do not have -- as i know nothing about the AMI amphibient Sep 13, 2012 at 19:12

... 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.

when I run sudo su as the ec2-user, it asks for a password. I have set no password myself. something to do with sudoers file maybe ? Ravi Sankar Raju Mar 21, 2013 at 11:04 @littlecegian The PDF above says, the user has the rights. I am not sure why it doesn't work in your case. Maybe relaunch the instance and try again or ask support for help. Till Mar 21, 2013 at 13:45

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
                inside /root/ssh/authorized_keys , 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) +11111
– Arthur Melo
                May 9, 2016 at 5:21
                "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)." This root cause clarification helps me a lot, thanks.
– user1097213
                Jun 22, 2017 at 9:21

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.

    thank you :) i needed to login as root to forward port 80 to my local machine, which i cannot do as ec2-user – necromancer Aug 3, 2014 at 8:51

    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
                    @Klaus In my case if I want to rsync whole instance to my home pc, so I think the modifying authorized_keys file is only solution (for syncing files that "ubuntu\ec2-user" user has no access to them)
    – Valentin Kantor
                    Dec 26, 2012 at 0:01
    

    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.

  • 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

  • Restart SSH

    sudo /etc/init.d/sshd restart

  • Change/set root password

    sudo passwd root

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

  • Exit current session and close PuTTY

  • Try again login as root and type previously set password.
  • 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

    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.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.