How do I set up SSH access for an Amazon EC2 instance?

后端 未结 13 1049
挽巷
挽巷 2021-01-29 19:20

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

相关标签:
13条回答
  • 2021-01-29 19:24

    To setup Ubuntu on AWS, please follow the following steps:

    1. Log-in to Amazon Web Services and select EC2.
    2. Choose Launch Instance and follow wizard by selecting the right image (Ubuntu), instance type, configuring VPC network and Subnet, storage and allowing SSH access in Security Groups. Then Launch.
    3. For the first time, you probably need to setup the key pair and assign it to the instance. You can also create key pair in Key Pairs. Once created, download the PEM file and keep it in a safe place.
    4. Once the instance is launched, wait until the instance is Initialized and running.

    To access the instance via SSH, run:

    1. Connect to Linux box by specifying your PEM file, e.g.

      ssh -i "file.pem" ubuntu@x.x.x.x
      

      Make sure your PEM file has 600 permission (chmod 600 file.pem).

    Troubleshooting

    If you're running VPC instance, and your security group is correct (with the right rules) and it still doesn't work, in VPC section check your subnet which should be attached to your VPC (both used by your instance) and setup new rule in Route Table that has 0.0.0.0/0 as Destination and your Internet Gateway as Target.

    For more details check: Troubleshooting Connecting to Your Instance

    See also: Possible reasons for timeout when trying to access EC2 instance

    0 讨论(0)
  • 2021-01-29 19:28

    Basically, you need a private-key file to login into your EC2 via SSH. Follow these steps to create one:

    • Go https://console.aws.amazon.com/ec2/home & sign in to your existing Amazon account.
    • Click on "Key Pairs" on LHS or https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs.
      • You should see the list of KEYs generated by you (or during EC2 creation process).
      • Click on "Create Key Pair" if you don't see any or you lost your private-key.
      • Enter a unique name and hit enter.
      • A download panel will appear for you to save the private-key, save it.
      • Keep it somewhere with the file permission "0600"
    • Click on "Instances" on LHS or https://console.aws.amazon.com/ec2/home?region=us-east-1#s=Instances
      • You should see the list of ec2-instances, if you don't see any, then please create one.
      • Click on the EC2 machine and note down the Public DNS address.
    • Open your Terminal (in Linux) and type the following command
      • ssh -i /path/to/private-key root@<ec2-public-dns-address> - the root username has been avoided in the latest releases, based on your distribution select ec2-user or ubuntu as your username.
      • hit Enter
      • That's it.
    0 讨论(0)
  • 2021-01-29 19:28

    STEP 1) Download private keys assigned to your ec2 machine (which is only one time download when created. so recommended to commit somewhere)

    STEP 2) and fire following commands,

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

    Official Doc : Connecting to Your Linux/Unix Instances Using SSH

    0 讨论(0)
  • 2021-01-29 19:29

    Note, the current user for 13.04 is "ubuntu" ssh -i ./mykey.pem ubuntu@ec2-xxx-xxx-xxx-1.compute-1.amazonaws.com

    0 讨论(0)
  • 2021-01-29 19:32

    Make sure these thing in check

    1. private key must have 400 permission

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

    3. ssh -i privatekey.pem ubuntu@XXX.XXX.XXX.XXX // XXX.XXX.XXX.XXX = your instance public ip
    0 讨论(0)
  • 2021-01-29 19:33

    1) First chmod the .pem file for restricting the file permissons as below

    chmod 400 my-key-pair.pem
    

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

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

    Note:- To navigate into .ssh folder. First press Ctrl + H to display all the hidden files and finallycd .ssh

    0 讨论(0)
提交回复
热议问题