Unable to SSH to the ubuntu managed node using instance-id

0

Dear all, I set up the session manager correctly a while ago. I was able to connect to my ubuntu-managed node through:

  • the System Manager Console
  • the AWS CLI ( Session manager Plugin is installed on my local Mac)
  • SSH using instance-id instead of host public IP I need the last one because I also need to transfer files between my local and the managed nodes. But after a few months, today I tried to connect using ssh:

ssh -i :path/to/file.pem ubuntu@{instance-id} But I'm not able to connect using ssh anymore ssh: Could not resolve hostname {instance-id}: nodename nor servname provided, or not known

The other starting session methods still work very fine and I am also able to SSH to the server using the host IP.

OS Version: Ubuntu 18.04.4 LTS

amazon-ssm-agent: 3.1.1188.0

Local AWS CLI: aws-cli/2.4.28 Python/3.8.8 Darwin/21.5.0 exe/x86_64 prompt/off

session-manager-plugin 1.2.295.0

Any help is really appreciated Regards Hamed.

  • Hello,

    Is there a chance that your instance was stopped at some point then you restarted it? Was it attached to an ElasticIP before stopping it? It could be that you IP address changed after starting your instance.

질문됨 2년 전612회 조회
2개 답변
1
수락된 답변

It appears that ssh is trying to resolve the instance id instead of starting the proxy command from ~/.ssh/config file. To allow SSH connections through Session Manager, the ssh configuration file must have a proxy command that starts a Session Manager session and transfer all data through the connection. Make sure that ssh config file for the logged in user ( in your Ubuntu machine) has following entry in it.

$ cat ~/.ssh/config

# SSH over Session Manager
host i-* mi-*
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"

For more details, refer to the following documentation.

https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html#ssh-connections-enable

profile pictureAWS
답변함 2년 전
  • Yes, that resolved my problem. Actually, it should be configured on the local ssh configuration. Thank you. Also, the needed policy permissions were missing for the SSH connection through the session manager.

0

Here is a tool designed exactly for that purpose: https://github.com/ivoronin/ec2ssh

답변함 4달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠