Trying to SSH into an Amazon Ec2 instance - permission error

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

    The issue for me was that my .pem file was in one of my NTFS partitions. I moved it to my linux partition (ext4).

    Gave required permissions by running:

    chmod 400 my_file.pem

    And it worked.

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

    You are likely using the wrong username to login:

    • most Ubuntu images have a user ubuntu
    • Amazon's AMI is ec2-user
    • most Debian images have either root or admin

    To login, you need to adjust your ssh command:

    ssh -l USERNAME_HERE -i .ssh/yourkey.pem public-ec2-host
    

    HTH

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

    SSH keys and file permission best practices:

    • .ssh directory - 0700 (only by owner)
    • private key/.pem file - 0400 (read only by owner)
    • public key/.pub file - 0600 (read & write only by owner)

      chmod XXXX file/directory

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

    Alternative log-in using PuTTY. Its good but needs a few steps.

    1. Get your .pem that was generated when you first made the EC2 instance.
    2. Convert the .pem file .ppk using PuttyGen since PuTTY does not read .pem.
    3. Open PuTTY and enter your Host Name which is your instance username + Public DNS (Ex. ubuntu@ec2-xxx-xxx-xxx-xxx.region.compute.amazonaws.com). Not your AWS account username.
    4. Then navigate to Connection > SSH > Auth. Then add your .ppk file. Click on Browse where it says "Private key file for authentication".
    5. Click Open and you should be able to immediately establish connection.

    Im using PuTTY 0.66 in Windows.

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

    Change permission for the key file with :

    chmod 400 key-file-name.pem
    

    See AWS documentation for connecting to the instance:

    http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#EC2_ConnectToInstance_Linux

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

    There can be three reasons behind this error.

    1. Your are using a wrong key.
    2. Your key doesn't have the correct permissions. You need to chmod it to 400.
    3. You are using the wrong user. Ubuntu images have a user ubuntu, Amazon's AMI is ec2-user and debian images have either root or admin
    0 讨论(0)
提交回复
热议问题