天天看點

SSH通路Amazon EC2執行個體時權限被拒絕(publickey)[關閉]

本文翻譯自:Permission denied (publickey) when SSH Access to Amazon EC2 instance [closed]

I want to use my Amazon ec2 instance but faced the following error:

我想使用我的Amazon ec2執行個體,但遇到以下錯誤:
Permission denied (publickey).
           

I have created my key pair and downloaded .pem file.

我建立了密鑰對并下載下傳了.pem檔案。

Given:

鑒于:
chmod  600 pem file.
           

Then, this command

然後,這個指令
ssh -i /home/kashif/serverkey.pem  [email protected]
           

But have this error:

但有這個錯誤:
Permission denied (publickey)
           

Also, how can I connect with filezilla to upload/download files?

另外, 如何連接配接filezilla上傳/下載下傳檔案?

#1樓

參考:https://stackoom.com/question/1Fq6e/SSH通路Amazon-EC-執行個體時權限被拒絕-publickey-關閉

#2樓

This error message means you failed to authenticate.

此錯誤消息表示您無法進行身份驗證。

These are common reasons that can cause that:

這些是導緻這種情況的常見原因:
  1. Trying to connect with the wrong key. 試圖用錯誤的密鑰連接配接。 Are you sure this instance is using this keypair? 你确定這個執行個體正在使用這個密鑰對嗎?
  2. Trying to connect with the wrong username. 試圖用錯誤的使用者名連接配接。

    ubuntu

    is the username for the ubuntu based AWS distribution, but on some others it's

    ec2-user

    (or

    admin

    on some Debians, according to Bogdan Kulbida's answer)(can also be

    root

    ,

    fedora

    , see below)

    ubuntu

    是基于ubuntu的AWS發行版的使用者名,但是對于其他一些

    ec2-user

    來說,它是

    ec2-user

    (或根據Bogdan Kulbida的回答

    admin

    一些Debian)(也可以是

    root

    fedora

    ,見下文)
  3. Trying to connect the wrong host. 試圖連接配接錯誤的主機。 Is that the right host you are trying to log in to? 這是您嘗試登入的正确主機嗎?

Note that

1.

will also happen if you have messed up the

/home/<username>/.ssh/authorized_keys

file on your EC2 instance.

需要注意的是

1.

也會發生,如果你搞砸了

/home/<username>/.ssh/authorized_keys

檔案,您的EC2執行個體。

About

2.

, the information about which username you should use is often lacking from the AMI Image description.

關于

2.

,您應該使用的使用者名資訊通常缺少AMI圖像描述。

But you can find some in AWS EC2 documentation, bullet point

4.

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

但您可以在AWS EC2文檔中找到一些内容,第

4.

點: http : //docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
Use the ssh command to connect to the instance. 使用ssh指令連接配接到執行個體。 You'll specify the private key (.pem) file and [email protected]_dns_name. 您将指定私鑰(.pem)檔案和user_name @ public_dns_name。 For Amazon Linux, the user name is ec2-user. 對于Amazon Linux,使用者名為ec2-user。 For RHEL5, the user name is either root or ec2-user . 對于RHEL5,使用者名是root或ec2-user 。 For Ubuntu, the user name is ubuntu . 對于Ubuntu,使用者名是ubuntu 。 For Fedora, the user name is either fedora or ec2-user . 對于Fedora,使用者名是fedora或ec2-user 。 For SUSE Linux, the user name is root . 對于SUSE Linux,使用者名為root 。 Otherwise, if ec2-user and root don't work, check with your AMI provider. 否則,如果ec2-user和root不起作用,請咨詢您的AMI提供商。

Finally , be aware that there are many other reasons why authentication would fail.

最後 ,請注意,身份驗證失敗還有許多其他原因。

SSH is usually pretty explicit about what went wrong if you care to add the

-v

option to your SSH command and read the output, as explained in many other answers to this question.

如果您需要将

-v

選項添加到SSH指令并讀取輸出,SSH通常非常明确地指出了什麼問題,正如此問題的許多其他答案中所解釋的那樣。

#3樓

I solved the problem just putting

sudo

before

我之前把

sudo

解決了問題
sudo ssh -i mykey.pem myec2.amazonaws.com
           

But the proper solution is to change the ownership first, and then connect as a normal user as Janus Troelsen said below.

但正确的解決方案是首先更改所有權,然後像Janus Troelsen所說的那樣以普通使用者身份進行連接配接。

In my case it would be:

在我的情況下,它将是:
chown wellington:wellington key.pem
           

#4樓

In this case the problem arises from lost Key Pair.

在這種情況下,問題是由丢失密鑰對引起的。

About this:

對這個:
  • There's no way to change Key Pair on an instance . 無法在執行個體上更改密鑰對 。 You have to create a new instance that uses a new Key Pair. 您必須建立一個使用新密鑰對的新執行個體。
  • You can work around the problem if your instance is used by an application on Elastic Beanstalk . 如果您的執行個體由Elastic Beanstalk上的應用程式使用,則可以解決此問題 。

You can follow these steps:

您可以按照以下步驟操作:
  1. Access to AWS Management Console 通路AWS管理控制台
  2. Open Elastic Beanstalk Tab 打開Elastic Beanstalk頁籤
  3. Select your application from All Applications Tab 從All Applications頁籤中選擇您的應用程式
  4. From left side menù select Configuration 從左側menù選擇配置
  5. Click on the Instances Gear 單擊Instances Gear
  6. In Server Form check the EC2 Key Pair input and select your new Key Pair. 在伺服器表單中,檢查EC2密鑰對輸入并選擇新的密鑰對。 You may have to refresh the list in order to see a new Key Pair you're just created. 您可能必須重新整理清單才能看到剛剛建立的新密鑰對。
  7. Save 儲存
  8. Elastic Beanstalk will create for you new instances associated with the new key pair. Elastic Beanstalk将為您建立與新密鑰對關聯的新執行個體。

In general, remember you have to allow your EC2 instance to accept inbound SSH traffic.

通常,請記住您必須允許EC2執行個體接受入站SSH流量。

To do this, you have to create a specific rule for the Security Group of your EC2 instance.

為此,您必須為EC2執行個體的安全組建立特定規則。

You can follow these steps.

您可以按照以下步驟操作。
  1. Access to AWS Management Console 通路AWS管理控制台
  2. Open EC2 Tab 打開EC2頁籤
  3. From Instances list select the instance you are interested in 從Instances清單中選擇您感興趣的執行個體
  4. In the Description Tab chek the name of the Security Group your instance is using. 在Description頁籤中, chek您的執行個體正在使用的安全組的名稱。
  5. Again in Description Tab click on View rules and check if your Security Group has a rule for inbound ssh traffic on port 22 再次在“ 描述”頁籤中,單擊“ 檢視規則”并檢查您的安全組是否在端口22上具有入站ssh流量規則
  6. If not, in Network & Security menù select Security Group 如果沒有,請在Network&Securitymenù中選擇安全組
  7. Select the Security Group used by your instance and the click Inbound Tab 選擇執行個體使用的安全組 ,然後單擊“ 入站”頁籤
  8. On the left of Inbound Tab you can compose a rule for SSH inbound traffic: 在“入站”頁籤的左側,您可以為SSH入站流量組成規則:
    • Create a new rule : SSH 建立新規則 :SSH
    • Source : IP address or subnetwork from which you want access to instance 來源 :您希望從中通路執行個體的IP位址或子網
    • Note : If you want grant unlimited access to your instance you can specify 0.0.0.0/0 , although Amazon not recommend this practice 注意 :如果您希望授予對執行個體的無限制通路權限 ,則可以指定0.0.0.0/0 ,盡管亞馬遜不推薦這種做法
  9. Click Add Rule and then Apply Your Changes 單擊添加規則 ,然後單擊應用您的更改
  10. Check if you're now able to connect to your instance via SSH. 檢查您現在是否能夠通過SSH連接配接到您的執行個體。

Hope this can help someone as helped me.

希望這能幫助有人幫助我。

#5樓

這就是我解決問題的方法

ssh -i <key> ec2-use[email protected]<ec2 ip>
           

#6樓

This has happened to me multiple times.

這種情況多次發生在我身上。

I have used Amazon Linux AMI 2013.09.2 and Ubuntu Server 12.04.3 LTS which are both on the free tier.

我使用的是Amazon Linux AMI 2013.09.2和Ubuntu Server 12.04.3 LTS,它們都是免費的。

Every time I have launched an instance I have permission denied show up.

我每次啟動一個執行個體時都會被拒絕顯示。

I haven't verified this but my theory is that the server is not completely set up before I try to ssh into it.

我還沒有驗證這一點,但我的理論是在嘗試ssh之前伺服器沒有完全設定。

After a few tries with permission denied, I wait a few minutes and then I am able to connect.

經過幾次嘗試拒絕許可後,我等了幾分鐘然後我才能連接配接。

If you are having this problem I suggest waiting five minutes and trying again.

如果你遇到這個問題我建議等五分鐘再試一次。

繼續閱讀