Trying to SSH into an Amazon Ec2 instance - permission error

后端 未结 29 3278
一生所求
一生所求 2020-11-27 08:51

This is probably a stupidly simple question to some :)

I\'ve created a new linux instance on Amazon EC2, and as part of that downloaded the .pem file to allow me to

相关标签:
29条回答
  • 2020-11-27 09:25

    Well, looking at your post description I feel there were 2 mistakes done by you:-

    1. Set correct permissions for the private key. Below command should help you to set correct file permision.

      chmod 0600 mykey.pem

    2. Wrong ec2 user you are trying to login.

      Looking at your debug log I think you have spawned an Amazon linux instance. The default user for that instance type is ec2-user . If the instance would have been ubuntu then your default user would have been ubuntu .

      ssh -i privatekey.pem default_ssh_user@server_ip

    Note:
       For an Amazon Linux AMI, the default user name is ec2-user.
    
       For a Centos AMI, the default user name is centos.
    
       For a Debian AMI, the default user name is admin or root.
    
       For a Fedora AMI, the default user name is ec2-user or fedora.
    
       For a RHEL AMI, the default user name is ec2-user or root.
    
       For a SUSE AMI, the default user name is ec2-user or root.
    
       For an Ubuntu AMI, the default user name is ubuntu.
    
       Otherwise, if ec2-user and root don't work, check with the AMI provider.
    

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

    0 讨论(0)
  • 2020-11-27 09:26

    I know this question has been answered already but for those that have tried them all and you are still getting the annoying "Permission denied (publickey)". Try running your command with SUDO. Of course this is a temporary solution and you should set permissions correctly but at least that will let you identify that your current user is not running with the privileges you need (as you assumed)

    sudo ssh -i amazonec2.pem ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com

    Once you do this you'll get a message like this:

    Please login as the user "ec2-user" rather than the user "root"

    Which is also sparsely documented. In that case just do this:

    sudo ssh -i amazonec2.pem ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com -l ec2-user

    And you'll get the glorious:

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|
    
    0 讨论(0)
  • 2020-11-27 09:27

    It is just a permission issue with your aws pem key.

    Just change the permission of pem key to 400 using below command.

    chmod 400 pemkeyname.pem
    

    If you don't have permission to change the permission of a file you can use sudo like below command.

    sudo chmod 400 pemkeyname.pem
    

    I hope this should work fine.

    0 讨论(0)
  • 2020-11-27 09:29

    I know this is very late to the game ... but this always works for me:

    step 1

    ssh-add ~/.ssh/KEY_PAIR_NAME.pem
    

    step 2, simply ssh in :)

    ssh user_name@<instance public dns/ip>
    

    e.g.

    ssh ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com
    

    hope this helps someone.

    0 讨论(0)
  • 2020-11-27 09:29

    .400 protects it by making it read only and only for the owner.
    You can find the answer from the ASW guide.

    chmod 400 yourPrivateKey.pem
    

    0 讨论(0)
  • 2020-11-27 09:30

    In windows you can go to the properties of the pem file, and go to the security tab, then to advance button.

    remove inheritance and all the permissions. then grant yourself the full control. after all SSL will not give you the same error again.

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