38

I've just setup my EC2 server following this video here exactly - http://www.youtube.com/watch?v=bBajLxeKqoY

I even chose the same server type, everything went well until it asked for the root password to my EC2 server...

Any suggestions?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Matt
  • 5,005
  • 10
  • 32
  • 39

18 Answers18

27

Update

Updating this answer because of the activity:

Depending on if the system is ubuntu or Rhel the user varies.

For ubuntu it is

ssh -i my-pem-file.pem ubuntu@my-ec2-instance-address

For RHEL it is

ssh -i my-pem-file.pem root@my-ec2-instance-address

Connecting to an ec2 instance does not require a password, it would require only a pem file and this is how you connect to it

ssh -i my-pem-file.pem ec2-user@my-instance-address

and remember to chmod 400 your pem file before ssh'ing

Dhiraj
  • 33,140
  • 10
  • 61
  • 78
19

If you need to do things as root once you are in as ec2-user, use sudo su - that gets you to root and doesn't need a password. Somethings you do need that for, like looking at the tomcat log files

Peter
  • 29,498
  • 21
  • 89
  • 122
13

I had the same problem and after a lot of struggle, I read this page again:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

Notice in the 4th topic it talks about the user name. It is usually ec2-user but if you are using RHEL5 distro it can be root and if you are using the Ubuntu the user name will be ubuntu - which was my case.

So alternatively try those:

ssh -i my-pem-file.pem ubuntu@my-ec2-instance-address for Ubuntu

or

ssh -i my-pem-file.pem root@my-ec2-instance-address for RHEL5

Hope it helps!

fagiani
  • 2,293
  • 2
  • 24
  • 31
  • 2
    The current CentOS AMI also requires an ssh user name of `root`. This runs counter to a lot of EC2 information that implies the user name is usually or always `ec2-user`. – Chris Johnson Mar 17 '14 at 23:14
  • 1
    Thanks for the advice it helped a lot. The user name for CoreOS is `core` – John Gilmer Dec 04 '16 at 00:03
5

You will be asked for password when you enable PasswordAuthentication yes in your sshd_config. Try changing that to no. that should fix it.

Just for anyone else that might have the same problem

Skillachie
  • 3,176
  • 1
  • 25
  • 26
5

Just do

     sudo su -

Worked for me

Stephen Ngethe
  • 1,034
  • 13
  • 24
4

If you've moved/copied the pem file from another machine, the owner of the file may be different to the user that is running the ssh client. To change the owner of the file:

sudo chown <currentusername> <filename.pem>
Steve S
  • 41
  • 1
4

Please use --query 'KeyMaterial' while generating key.

Info:

keyMaterial - an unencrypted PEM encoded RSA private key.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Sharath Arakere
  • 129
  • 2
  • 9
  • This is exactly what I was after, as I was having this issue because of a self-inflicted AWS CLI flaw on my part, live and learn, thanks for posting this answer even though others were offering user/permissions solutions! Further documentation found here: http://docs.aws.amazon.com/cli/latest/userguide/cli-ec2-keypairs.html#creating-a-key-pair – TryTryAgain Sep 21 '17 at 06:37
3

In my case, we had been copying a text file to keep a ubiquitous key. Someone accidentally added characters to this file, and we started getting prompted for a password from the now-corrupt .pem file, when we had never set a password.

ambe5960
  • 1,870
  • 2
  • 19
  • 47
2
chmod 400 pem_file

ssh -i /path_to_the_pem_file ec2-user@ServerIP

or

ssh -i /path_to_the_pem_file ubuntu@ServerIP

root access is prohibited by default by AWS AMIs.

hope it helps.

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
CloudGuy
  • 120
  • 4
2

In my case, the problem was the file's break type. Try this:

1.- Open the .pem file with TextWrangler

2.- At Bottom of app, verify if the Break Type is "Windows(CRLF)".

Regards

pmartinezd
  • 31
  • 1
2

This is the way to connect:

ssh -i /path/my-key-pair.pem ec2-user@public-ip

Now, instead of ec2-user, it could be root, or centos, or ubuntu, or something else. You can check under the "Usage Instructions". If it's not there, and you've tried all the above users, find out from the documentation that came with the AMI.

There is one bug on AWS that cost me a lot of time. If you're launching an instance from a saved AMI under "Images > AMIs", note that it uses the original keys of the running instance it was created from. When launching the AMI, it will prompt you to choose a new key, and even show such key under the description, but the truth is those keys will never work!

So if you're using a custom/saved AMI you'll have to either get the original keys and use them, or just create a brand new one from AWS or the market place. If you haven't created the AMI or can't remember where it came from, look under the details tab. You can then launch a new instance or create a new AMI from the same source. This will then use the keys that you specify.

Nagev
  • 10,835
  • 4
  • 58
  • 69
1

Check your .pem file is not corrupt. Using this line

openssl rsa -check -in test.pem -noout

It should return RSA Key OK. If it doesn't then there is most likely a problem with some sort of formatting or something in your pem file.

Ega
  • 437
  • 4
  • 12
0

It could be a Linux problem. But there is also a chance that you use the wrong address/key (you started a new instance but still using the old address; or 2 pem have similar name, used the wrong one), "ssh with non-existing user".

Community
  • 1
  • 1
Mzq
  • 1,796
  • 4
  • 30
  • 65
0

I am using TurboLinux instance, on Mac OS system, please try this command: ssh -i xxxxx.pem root@xxx.xxx.xxx.xxx (public address of allocated VM) I can get through without asking password anymore.

Luke Teng
  • 1
  • 1
0

In case someone else bumps into this, the solution for my problem was that I had to run it with sudo:

sudo ssh -i my-pem-file.pem root@my-ec2-instance-address
Nick Zinger
  • 1,174
  • 1
  • 12
  • 28
0

For me, the issue was that I had created an AMI from an existing instance, so when I launched the AMI, even though I selected a new key, the instance's original key was what worked.

storm_m2138
  • 2,281
  • 2
  • 20
  • 18
0

Login to Amazone console in browser: https://us-east-2.console.aws.amazon.com/ec2/xxxxxxxx

Click on instances from left panel -> then select your instance -> click on connect button at top right

You will see a window open and there will be a button ssh Client

Here you can see exact command to connect with your instance.

flik
  • 3,433
  • 2
  • 20
  • 30
0

You should use the *.pem instead of a root password. Once you have logged in use passwd to set a password.

Mikhail
  • 7,749
  • 11
  • 62
  • 136
  • 1
    I am using the pem file, and it's still asking for a password? unless trying to ssh with the pem on a different computer matters? – Matt Mar 17 '12 at 06:19
  • 1
    If you use the *pem it will not ask for a password by default. Try specifying the user as "ec2-user" or "root" in the ssh command. What client and client operating system are you using? Did you restrict the ec2 access to only certain IPs? – Mikhail Mar 17 '12 at 06:20
  • I did not, or I don't think I did, I just followed that video exactly. I tried root at ec2-user...I'm using ubuntu and just terminal – Matt Mar 17 '12 at 06:22
  • ssh -i my.pem ec2-user@myip.com – Mikhail Mar 17 '12 at 06:24
  • Probably using the wrong pem. Make a new image and try to use the Amazon interface. – Mikhail Mar 17 '12 at 06:27
  • 3
    I had the same problem when logging in as `root`, but the image was configured such that the login should be `ubuntu`. – Eric J. Mar 17 '12 at 06:28
  • Is it asking for a root password or did you set a password phrase on your pem? – mac Mar 18 '12 at 07:21
  • I'm having the same problem. This is the log in prompt of the Red Hat server – Attila Szeremi Jan 30 '14 at 12:58