Search code examples
amazon-web-servicessshaws-ssm

How to do a SSH to another instance, after getting access to current instance using AWS SSM?


I am using AWS and we have a EC2 set up, which we can use AWS Session Manager with. I am able to gain access to this system, but from here I want to access other private EC2 instances.

Host A (Logged in via SSM)  ----> Host B

(In these instances, many others like Host B don't have SSM set up right now.)

From here I try, to

ssh ec2-user@HostB

but this fails cause, it requires a PEM file.

I have access to this file on my local machine, but can't figure out how to send that file to Host A so I can use it to SSH into Host B


Solution

  • Simply copy the contents of the PEM file to your clipboard. Then, use SSM to connect to the other instance and save it to a file.

    You can run an editor (eg vi), or just use cat >key.pem then paste your clipboard and type Ctrl-D.

    You'll also need to chmod 600 key.pem.

    To connect, use:

    ssh -i key.pem ec2-user@HostB
    

    Another method is to copy the file to S3 and then download it from S3.