Trying to SSH into an Amazon Ec2 instance - permission error

后端 未结 29 3254
一生所求
一生所求 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:20

    In addition to the other answers, here is what I did in order for this to work:

    • Copy the key to .ssh folder if you still hadn't:

    cp key.pem ~/.ssh/key.pem

    • Give the proper permissions to the key

    chmod 400 ~/.ssh/key.pem

    • Start ssh-agent (Thanks to https://stackoverflow.com/a/17848593 )

    eval `ssh-agent -s` ssh-add

    • Then, add the key

    ssh-add ~/.ssh/key.pem

    Now you should be able to ssh EC2 (:

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

    What did it for me is editing the default security group to allow for inbound TCP traffic at port 22:

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

    BY default permission are not allowing the pem key. You just have to change the permission:

    chmod 400 xyz.pem

    and if ubuntu instance then connect using:

    ssh -i xyz.pem ubuntu@ec2-youraws.amazonaws.com

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

    In Mac terminal, doing "chmod 400 xyz.pem" did not help me, it kept saying permission denied. For ubuntu users I would suggest

    1. ssh-add xyz.pem
    2. ssh -i xyz.pem ubuntu@ec2-54-69-172-118.us-west-2.compute.amazonaws.com (notice the user is ubuntu)
    0 讨论(0)
  • 2020-11-27 09:23

    Key file should not be publicly viewable so use permission 400

    chmod 400 keyfile.pem
    

    If above command shows permission error use

    sudo chmod 400 keyfile.pem
    

    Now ssh into the ec2 machine, if you still face the issue, use ec2-user

    ssh -i keyfile.pem ec2-user@ec2-12-34-56-78.compute-1.amazonaws.com

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

    In windows,

    • Right click on the pem file. Then select properties.
    • Select security tab --> Click on Edit --> Remove all other user except current user
    • Go back to security tab again --> Click on Advanced --> Disable inheritance
    0 讨论(0)
提交回复
热议问题