how to login to ec2 machine?

前端 未结 5 1596
借酒劲吻你
借酒劲吻你 2021-01-30 21:03

I was given some login information for an EC2 machine, basically an ec2-X-X-X.compute-X.amazonaws.com plus a username and password.

How do I access the machine? I tried

相关标签:
5条回答
  • 2021-01-30 21:33

    Indeed EC2 (Amazon Elastic Compute Cloud) does not allow password authentication to their instances (linux machines) by default.

    The only allowed authentication method is with an SSH key that is created when you create the instance. During creation they allow you to download the SSH key just once, so if you loose it, then you have to regenerate it.

    This SSH key is only for the primary user - usually named

    • "ec2-user" (Amazon Linux, Red Hat Linux, SUSE Linux)
    • "root" (Red Hat Linux, SUSE Linux)
    • "ubuntu" (Ubuntu Linux distribution)
    • "fedora" (Fedora Linux distribution)

    or similar (depending on distribution)

    See connection instructions: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html

    If you want to add a new user the recommended way is to generate and add a new SSH key for the new user, but not specify a password (which would be useless anyway since password authentication is not enabled by default).

    Managing additional users: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html

    After all if you want to enable password authentication, which lowers down the security and is not recommended, but still you might need to do that for your own specific reasons, then just edit

    /etc/ssh/sshd_config
    

    For example: sudo vim /etc/ssh/sshd_config

    find the line that says:

    PasswordAuthentication no
    

    and change it to

    PasswordAuthentication yes
    

    Then restart the instance

    sudo reboot 
    

    After restarting, you are free to create additional users with password authentication.

    sudo useradd newuser
    sudo passwd newuser
    

    Add the new user to the sudoers list:

    sudo usermod -a -G sudo newuser
    

    Make sure user home folder exists and is owned by the user

    sudo mkdir /home/newuser
    sudo chown newuser:newuser /home/newuser
    

    New you are ready to try and login with newuser via ssh. Authentication with ssh keys will continue to work in parallel with password authentication.

    0 讨论(0)
  • 2021-01-30 21:35

    Our Amazon AMI says to "Please login as the ec2-user user rather than root user.", so it looks like each image may have a different login user, e.g.

    ssh -i ~/.ssh/mykey.pem ec2-user@ec2-NN-NNN-NN-NN.us-foo-N.compute.amazonaws.com
    

    In short, try root and it will tell you what user you should login as.

    [Edit] I'm supposing that you don't have AWS management console credentials for the account, but if you do, then you can navigate to the EC2->Instances panel of AWS Management Console, right click on the machine name and select "Connect..." A list of the available options for logging in will be displayed. You will (or should) need a key to access an instance via ssh. You should have been given this or else it may need to be generated.

    If it's a Windows instance, you may need to use Remote Desktop Connection to connect using the IP or host name, and then you'll also need a Windows account login and password.

    0 讨论(0)
  • 2021-01-30 21:48

    For this you need to be have a private key it's like keyname.pem.

    Open the terminal using ctrl+alt+t.

    change the file permission as a 400 or 600 using command chmod 400 keyname.pem or chmod 600 keyname.pem

    Open the port 22 in security group.

    fire the command on terminal ssh -i keyname.pem username@ec2-X-X-X.compute-X.amazonaws.com

    0 讨论(0)
  • 2021-01-30 21:50

    If you are new to AWS and need to access a brand new EC2 instance via ssh, keep in mind that you also need to allow incoming traffic on port 22.

    Assuming that the EC2 instance was created accepting all the default wizard suggestions, access to the machine will be guarded by the default security group, which basically prohibits all inbound traffic. Thus:

    1. Go to the AWS console
    2. Choose Security Groups on the left navigation pane
    3. Choose default from the main pane (it may be the only item in the list)
    4. In the bottom pane, choose Inbound, then Create a new rule: SSH
    5. Click Add rule and then Apply Rule Changes

    Next, assuming that you are in possession of the private key, do the following:

    $ chmod 600 path/to/mykey.pem
    $ ssh -i path/to/mykey.pem root@ec2-X-X-X.compute-X.amazonaws.com
    

    My EC2 instance was created from a Ubuntu 32-bit 12.04 image, whose configuration does not allow ssh access to root, and asks you to log in as ubuntu instead:

    $ ssh -i path/to/mykey.pem ubuntu@ec2-X-X-X.compute-X.amazonaws.com
    

    Cheers, Giuseppe

    0 讨论(0)
  • 2021-01-30 21:50

    The process of connecting to an AWS EC2 Linux instance via SSH is covered step-by-step (including the points mentioned below) in this video.

    To correct this particular issue with SSH-ing to your EC2 instance:

    1. The ssh command you ran is not in the correct format. It should be:

      ssh -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com
      
    2. Note, you need access to the private key (.pem) file to use in the command above. AWS prompts you to download this file when you first launch your instance. You will need to run the following command to ensure that only your root user has read-access to it:

      chmod 400 /path/to/yourKeyFile.pem
      
    3. Depending on your Linux distribution, the user you need to specify when you run ssh may be one of the following:

      • For Amazon Linux, the user name is ec2-user.
      • For RHEL, the user name is ec2-user or root.
      • For Ubuntu, the user name is ubuntu or root.
      • For Centos, the user name is centos.
      • For Fedora, the user name is ec2-user.
      • For SUSE, the user name is ec2-user or root.
      • Otherwise, if ec2-user and root don't work, check with your AMI provider.
    4. You need to enable an inbound SSH firewall. This can be done under the Security Groups section of AWS. Full details for this piece can be found here.

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