如何使用 aws cli 连接 aws 实例?

如何使用 aws cli 连接 aws 实例?

我没有 ssh 密钥,但我可以访问 ec2 机器所在的 aws 门户和控制台。

我尝试使用此处的步骤关联连接 ec2 实例。

方法 1:

仅使用 instance-id 和 mssh

mssh i-038317982dc6a7c64
Unable to init server: Could not connect: Connection refused

(mssh:2876): Gtk-WARNING **: 14:03:20.071: cannot open display:

方法 2:生成新的 ssh 密钥并将其推送到 ec2 实例。

aws ec2-instance-connect send-ssh-public-key     --instance-id i-038317982dc6a7c64     --availability-zone us-east-1b    --instance-os-user ec2-user     --ssh-public-key file://my_key.pub

An error occurred (EC2InstanceNotFoundException) when calling the SendSSHPublicKey operation: Instance not found.

但是那台机器就在那里。

因此我也尝试提供区域。

aws ec2-instance-connect send-ssh-public-key     --instance-id i-038317982dc6a7c64     --availability-zone us-east-1b --region us-east-1    --instance-os-user ec2-user     --ssh-public-key file://my_key.pub
{
    "RequestId": "9ecd1748-1ef3-4b7b-b1a5-5ae4370df452",
    "Success": true
}

然后,我尝试使用 ssh 连接。

但是对于 DNS 名称或 IP 地址,我仅得到了权限被拒绝的结果。

ssh -o "IdentitiesOnly=yes" -i my_key [email protected]
The authenticity of host '54.174.85.61 (54.174.85.61)' can't be established.
ECDSA key fingerprint is SHA256:7hTrm5wLeicqFVbNG9MW7HDEqUZQDi/H/OzJ3AwL0zU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '54.174.85.61' (ECDSA) to the list of known hosts.
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).



ssh -o "IdentitiesOnly=yes" -i my_key [email protected]
    The authenticity of host 'ec2-54-174-85-61.compute-1.amazonaws.com (54.174.85.61)' can't be established.
    ECDSA key fingerprint is SHA256:7hTrm5wLeicqFVbNG9MW7HDEqUZQDi/H/OzJ3AwL0zU.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'ec2-54-174-85-61.compute-1.amazonaws.com' (ECDSA) to the list of known hosts.
    [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

请建议有哪些选项可用于连接 aws linux 2 机器,并在控制台中配置 aws 凭证,并具有 instanceid/machine dns 名称或 ip 地址

相关内容