如何通过ssh连接到AWS实例?
我有:
在AWS注册;
在AWS网站上创建公钥和证书并将其保存到磁盘;
去了我的控制台并创建了环境变量:
$ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/ $ export EC2_CERT=/home/default/aws/cert-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem $ export EC2_PRIVATE_KEY=/home/default/aws/pk-EBAINCRNWHDSCWWIHSOKON2YWGJZ5LSQ.pem
告诉AWS API使用此密钥对并将密钥对保存到文件:
$ ec2-add-keypair ec2-keypair > ec2-keypair.pem
使用此密钥对启动AWS Ubuntu 9实例:
$ ec2-run-instances ami-ed46a784 -k ec2-keypair
尝试与实例建立ssh连接:
$ ssh -v -i ec2-keypair.pem ubuntu@ec2-174-129-185-190.compute-1.amazonaws.com OpenSSH_5.1p1 Debian-5ubuntu1, OpenSSL 0.9.8g 19 Oct 2007 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to ec2-174-129-185-190.compute-1.amazonaws.com [174.129.185.190] port 22. debug1: Connection established. debug1: identity file ec2-keypair.pem type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5ubuntu1 debug1: match: OpenSSH_5.1p1 Debian-5ubuntu1 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-cbc hmac-md5 none debug1: kex: client->server aes128-cbc 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: Host 'ec2-174-129-185-190.compute-1.amazonaws.com' is known and matches the RSA host key. debug1: Found key in /home/default/.ssh/known_hosts:11 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: ec2-keypair.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).
可能是什么问题以及如何使其发挥作用?
sipwiz.. 501
对于Ubuntu实例:
chmod 600 ec2-keypair.pem ssh -v -i ec2-keypair.pem ubuntu@ec2-174-129-185-190.compute-1.amazonaws.com
对于其他情况,您可能必须使用ec2-user
而不是ubuntu
.
我使用的大多数EC2 Linux映像都默认创建了root用户.
另请参阅:http://www.youtube.com/watch?v = WBro0TEAd7g
对于Ubuntu实例:
chmod 600 ec2-keypair.pem ssh -v -i ec2-keypair.pem ubuntu@ec2-174-129-185-190.compute-1.amazonaws.com
对于其他情况,您可能必须使用ec2-user
而不是ubuntu
.
我使用的大多数EC2 Linux映像都默认创建了root用户.
另请参阅:http://www.youtube.com/watch?v = WBro0TEAd7g
现在是:
ssh -v -i ec2-keypair.pem ec2-user@[yourdnsaddress]
Canonical的版本默认使用用户'ubuntu'来登陆这里的任何人使用ubuntu图像来解决同样的问题.
如果您使用的是Bitnami图像,请以"bitnami"身份登录.
看似显而易见,但我忽视了一些事情.
对于我的ubuntu图像,它实际上是ubuntu用户而不是ec2用户;)
Ubuntu 10.04与openSSH
这是确切的用法:
ssh -v -i [yourkeypairfile] ec2-user@[yourdnsaddress]
例如:
ssh -v -i GSG_Keypair.pem ec2-user@ec2-184-72-204-112.compute-1.amazonaws.com
以上示例直接来自AWS教程,用于连接到Linux/UNIX计算机:http: //docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/
如果pem文件权限太开放,它也会抱怨.chmod文件到600来解决这个问题.
我也遇到了这个问题-原来我正在使用社区创建的AMI-默认用户名是niehter root,也不是ect-user或ubuntu。实际上,我不知道它是什么-直到尝试了“ root ”,服务器好心地要求我以xxx身份登录,其中xxx告诉您什么。
-干杯!