5

I am trying my experience with Amazon EC2, but unable to connect to the server. After creating PEM file inside Amazon Management Console, then I create private key using PuttyGen. Using Putty, I tried to connect using newly created private key.

But it prompt me login as: and I entered "root". Then it gave me error "PLEASE EC2 login as EC2 user other than root"

Any idea which user is the error referring to -- since I don't see any user creation page at AWS management console?

Thanks

5 Answers 5

6

The "root" account has been disabled. Where you entered "root" before, enter "ec2-user" instead and you'll be in. Once you're in, if you need to run a command as root, put "sudo" in front of the command.

eg:

sudo nc -l 80

or to get a console as root:

sudo bash
1
  • hi Jim, i have same issue using MacBook while trying to connect using ssh, and it is resolved by changing root to ec2-user.. thanks!
    – iwan
    Aug 30, 2011 at 8:57
5

If you want to be able to login as root into a prebuilt Amazon AMI, you need to do two things, these commands should be run as root.

  1. Edit the /etc/ssh/sshd_config file and change the line that says 'PermitRootLogin No' to 'PermitRootLogin without-password'. Then restart the sshd client with 'service sshd restart'. Be careful, if you screw up the sshd file, it is possible you will only have your current ssh session to fix it, so always test any changes with a second session.

  2. Edit the /root/.ssh/authorized_keys file. The first (and only) entry starts with 'command ... sleep 10; ssh-rsa [big long key]'. If you remove the text from the beginning of the line until where it says ssh-rsa, you will be able to login as root via SSH with your Amazon keypair.

2
  • I discovered that is is essential to enable root login on instance storage instances as there is no way to fix anything if one is locked out! Worst - I once messed my sudoers file and had to terminate the instance. stackoverflow.com/a/4336527/482176 is a good answer too.
    – Lord Loh.
    Apr 11, 2012 at 19:06
  • Logging in as root is disabled as a security precaution. It is simple for ec2-user to gain root priviledges with sudo su on the command line. Jul 6, 2017 at 13:06
2

Just insert ec2-user in the data section of your putty configuration.

1
  • hi Juan.. thanks for sharing your thought.. but it did not work.
    – iwan
    Nov 28, 2010 at 15:24
1

It sounds like that's something specific to the AMI you're loading your EC2 instance from. Most AMI's use root as the default user setup but that is dependent on how the AMI instance. In most cases this is simply root and it leaves you to create any additional users. I for instance have root installed in the AMI and have the SSH key installed on boot-up and then allow other users to be configured via Puppet. If you built your AMI with SSH configured to disallow root login then you would obviously need an alternative user to be setup so you could log in successfully.

2
  • hi Jeremy.. i tried to create another AMI, but still having the same problem..
    – iwan
    Nov 28, 2010 at 15:25
  • Then i finally solve it by using cygwin-ssh , i think it's a problem with my putty.. because it should not prompt with any login if it read the private key correctly.. i still don't know where the fault is
    – iwan
    Nov 28, 2010 at 15:26
1

I noticed the solution to this problem was in putty, where you put your long connection name like:

ec2-50-11-111-111.compute-1.amazonaws.com

you can use

[email protected]

and that error goes away and you are logged in as whatever username you put in front of the @ sign

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .