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 Antworten
1
Akzeptierte Antwort

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
beantwortet vor 2 Jahren
  • 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

beantwortet vor 9 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen