How to configure SSH access for an Amazon EC2 instance?

I need SSH access to an Amazon EC2 instance running Ubuntu 10.4. All I have is an Amazon username and password. Any ideas?

+83
ubuntu amazon-ec2
Jun 18 '11 at 8:17
source share
13 answers

Basically, you need a secret key file to log into your EC2 via SSH. To create it, follow these steps:

  • Go to https://console.aws.amazon.com/ec2/home and log in to your existing Amazon account.
  • Click "Key Pairs" on LHS or https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs .
    • You should see a list of the keys you generate (or during the creation of EC2).
    • Click "Create key pair" if you do not see or you have lost your secret key.
    • Enter a unique name and press enter.
    • A download panel will appear to save the secret key, save it.
    • Store it somewhere with a file resolution of "0600"
  • Click "Instances" on LHS or https://console.aws.amazon.com/ec2/home?region=us-east-1#s=Instances
    • You should see a list of ec2 instances, if you do not see it, please create one.
    • Click on the EC2 machine and write down the public DNS address.
  • Open a terminal (on Linux) and enter the following command
    • ssh -i /path/to/private-key root@<ec2-public-dns-address> - the root username has been excluded in recent versions, based on your distribution, select ec2-user or ubuntu as your username.
    • press Enter
    • What is it.
+155
Jun 20 '11 at 6:40
source share
 ssh -i /path/to/private-key ubuntu@<ec2-public-dns-address> 

just use ubuntu instead of root . Your problem will be resolved. Hurrah!

+23
Aug 21 '13 at 0:01
source share

STEP 1) Download the private keys assigned to your ec2 computer (which only loads once upon creation, so it is recommended to commit something)

STEP 2) and execute the following commands:

 chmod 400 MyKeyPair.pem ssh -i MyKeyPair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com 

White Paper : Connecting to Your Linux / Unix Instances Using SSH

+10
Jun 06 '14 at 20:51
source share

Please note that the current user for 13.04 is ubuntu ssh -i./mykey.pem ubuntu@ec2-xxx-xxx-xxx-1.compute-1.amazonaws.com

+7
Aug 09 '13 at 14:18
source share

First you need to create a key pair - do it using the EC2 console. Then use your private key for SSH on the server (username ec2-user ) using the SSH client of your choice.

After logging in, you can issue sudo su - to get root if you want (note: you cannot log in as root directly).

+4
Jun 19 '11 at 19:06
source share

If you are using MacOS, you should create / modify the SSH configuration file (~ / .ssh / config) and put something like:

 Host *.amazonaws.com User ubuntu Port 22 StrictHostKeyChecking no UserKnownHostsFile=/dev/null IdentityFile ~/PATH/YOUR_DOWNLOADED_KEY.pem 

Then connect to any instance of EC2:

 ssh MYNAME.amazonaws.com 

Nothing more!

+3
Feb 10 '15 at 19:47
source share

To configure Ubuntu on AWS, follow these steps:

  • Log in to Amazon Web Services and select EC2.
  • Select "Launch Instance" and follow the wizard's instructions, choosing the correct image (Ubuntu), type of instance, setting up the VPC network and subnet, storage and allowing SSH access in security groups. Then run.
  • For the first time, you probably need to configure a key pair and assign it to an instance. You can also create a key pair in Key Pairs. Once created, download the PEM file and save it in a safe place.
  • After starting the instance, wait while the instance is initialized and started.

To access the instance through SSH, run:

  • Connect to Linux by specifying your PEM file, for example

     ssh -i "file.pem" ubuntu@xxxx 

    Make sure your PEM file has a resolution of 600 ( chmod 600 file.pem ).

Troubleshooting

If you are using a VPC instance and your security group is correct (with the correct rules) and it still does not work, in the VPC section check your subnet , which should be attached to your VPC (both are used by your instance) and configure the new rule in route table , where 0.0.0.0/0 as the destination and your Internet gateway as the target.

Read More: Troubleshooting Connecting to Your Instance

See also: Possible timeout causes when trying to access an EC2 instance

+1
Jun 12 '16 at 14:41
source share

1) First chmod .pem file to restrict file permissions as shown below

 chmod 400 my-key-pair.pem 

2) Then ssh with the following commands directly from the .ssh folder

ssh -i my-key-pair.pem ec2-user@ec2-198-99-90-3.compute-1.amazonaws.com

Note. . To go to the .ssh folder. First press Ctrl + H to display all hidden files and finally cd .ssh

+1
May 05 '17 at 18:59
source share

Do not log in as the correct user for you may be a problem with Distro. For a specific new AMI, the username may not be ubuntu, but ec2-user. For example, for Amazon Linux, the user is "ec2-user". Eric Hammond gives examples here: http://alestic.com/2014/01/ec2-ssh-username

My suggestion, try:

 ssh -i /path/to/file.pem ec2-user@ec2... ssh -i /path/to/file.pem ubuntu@ec2... ssh -i /path/to/file.pem root@ec2... 

If you have the wrong AMI, you can simply simply restart the machine so that you have uniformity among your clusters. If this is your problem, you will probably need the same Distro OS, at least for your linux boxes.

0
Jun 01 '14 at 23:38
source share

Doing what is suggested in all of these answers is not enough. Against each instance, you see a security group. When you start a new instance, you will have this object installed by default. You need to edit the security group and add the ssh port to it. Later you need to add ports 8080, 8443, 80, 443 if you want to host your site.

0
Nov 27 '14 at 13:17
source share

Make sure these things are in check

  1. private key must have permission 400

  2. Make sure port 22 is open for the AWS instance you are trying to access.

  3. ssh -i privatekey.pem ubuntu@XXX.XXX.XXX.XXX //XXX.XXX.XXX.XXX = your public instance ip
0
Apr 25 '15 at 11:02
source share

I accepted the AWS proposal to use default security groups that included All Trafic ports.

And, after many, many attempts to connect to my new instance of ec2, I just realized that I had to edit my security group in use and manually add it to the incoming and outgoing 22nd port (ssh)!

Hope this helps!

0
Jun 11 '15 at 23:21
source share

The first permission to change the pem file to

 chmod 400 path/to/key_pair.pem 

Inside the ~ / .ssh / config file, add the following lines at the top of the file

 Host AWS Hostname myserver.com User myuser IdentityFile path/to/.pem/file port 22 

The host name accepts the IP or server link, the user accepts the username and the Identity file is the file downloaded from AWS when the instance was created. Just run the following command in terminal

 ssh AWS 

and enjoy!

Note To go to the .ssh folder. First press Ctrl + H in the home folder to display all hidden files and finally cd .ssh

0
Aug 16 '17 at 7:36 on
source share



All Articles