具有主機別名的 AWS SSM SSH 未如預期運作

具有主機別名的 AWS SSM SSH 未如預期運作

我想知道為什麼這個命令有效(1):

ssh -i .ssh/my-dev.pem ubuntu@i-1234abc

但該指令失敗並出現下列錯誤 (2):

ssh myec2

錯誤是:

An error occurred (TargetNotConnected) when calling the StartSession operation: myec2 is not connected.
Connection closed by UNKNOWN port 65535

這是我的.ssh/config

Host myec2
    User ubuntu
    HostName i-1234abc
    IdentityFile ~/.ssh/my-dev.pem
    ProxyCommand sh -c "aws --profile myawsprofile --region us-east-1 ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
 
Host i-* mi-*
    IdentityFile ~/.ssh/my-dev.pem
    ProxyCommand sh -c "aws --profile myawsprofile --region us-east-1 ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"

根據我的理解,使用上述配置運行命令(2)應該與命令(1)相同。所以有件事我不懂。

相關內容