2013-10-02 114 views
0

我想SSH到EC實例。SSH連接到EC2實例

這些是我遵循的步驟,下面是我得到的錯誤。

  1. 在亞馬遜控制檯中,我創建了一個密鑰對,並下載了它

  2. 改變了PEM文件的權限,以400(書面here

  3. 又到正在運行的實例中控制檯並得到了我的公共DNS

  4. 向描述爲'SecurityGroup for ElasticBeanstalk environment'的組添加入站規則(SSH),0.0.0.0/0。在控制檯中的安全組選項卡

  5. 在控制檯ssh -i <>my_key_filename>.pem [email protected]<Public DNS>

執行該這是對於輸出:

OpenSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: Connecting to ec2-54-254-148-94.ap-southeast-1.compute.amazonaws.com [54.254.148.94] port 22. 
debug1: Connection established. 
debug1: identity file mykey.pem type -1 
debug1: identity file mykey.pem-cert type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 
debug1: match: OpenSSH_5.3 pat OpenSSH_5* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP 
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY 
debug1: Server host key: RSA a1:2b:92:f6:cf:e3:ed:8a:60:0e:34:c0:27:24:6f:f7 
The authenticity of host 'ec2-54-254-148-94.ap-southeast-1.compute.amazonaws.com (54.254.148.94)' can't be established. 
RSA key fingerprint is a1:2b:92:f6:cf:e3:ed:8a:60:0e:34:c0:27:24:6f:f7. 
Are you sure you want to continue connecting (yes/no)? yes 
Warning: Permanently added 'ec2-54-254-148-94.ap-southeast-1.compute.amazonaws.com,54.254.148.94' (RSA) to the list of known hosts. 
debug1: ssh_rsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: Roaming not allowed by server 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey 
debug1: Next authentication method: publickey 
debug1: Offering RSA public key: aws_key.pem 
debug1: Authentications that can continue: publickey 
debug1: Offering DSA public key: id_dsa 
debug1: Authentications that can continue: publickey 
debug1: Offering RSA public key: [email protected] 
debug1: Authentications that can continue: publickey 
debug1: Trying private key: mykey.pem 
debug1: read PEM private key done: type RSA 
debug1: Authentications that can continue: publickey 
debug1: No more authentication methods to try. 
Permission denied (publickey). 

此外,我試圖連接到的實例一個Amazon Linux實例。

+0

從你動作的順序並不清楚您所創建的實例*後*創建密鑰對。該實例應該已經使用該密鑰對設置啓動。 – Froyke

+0

是的,我首先關注了[this](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html)。之後我創建了密鑰對,然後嘗試使用該密鑰對連接到該實例。這是它應該如何工作? – Albin

回答

1

從您的問題下面的評論:它看起來像你的步驟順序不正確。

  • 首先,你需要創建密鑰對
  • ,那麼你需要告訴ElasticBeanstak使用該密鑰對的時候就會啓動實例

公共密鑰注入到在第一次啓動的實例。 AWS不可能在實例啓動後更改密鑰對- AWS沒有技術方法連接到您的實例。 (你可以手動上傳文件~/.ssh目錄做)

要了解更多有關如何與ElasticBeanstalk使用密鑰對,看看這張截圖 enter image description here

或者只是創建一個.ebextensions目錄與application.config文件包含有關自定義ElasticBeanstalk環境

- namespace: aws:autoscaling:launchconfiguration 
    option_name: EC2Keyname 
    value: "keyname" 

更多細節:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-options

個可能的值列在這裏可以在這裏找到http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-launchconfig.html

更多細節密鑰對:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html

--Seb