qoomon / aws-ssm-ec2-proxy-command

AWS SSM EC2 SSH Proxy Command
MIT License
213 stars 73 forks source link

support for custom ssh'key pair doesn't seem to work #19

Closed ideallical closed 1 year ago

ideallical commented 1 year ago

Thanks for this script. It works using the default id_rsa key pair.

However, if I use any other ssh private/public key pair than the default id_rsa, it doesn't seem to work:

Host i-* mi-*
  IdentityFile ~/.ssh/name-of-custom-key
  ProxyCommand ~/.ssh/aws-ssm-ec2-proxy-command.sh %h %r %p ~/.ssh/name-of-custom-key.pub
  StrictHostKeyChecking no

Could it be that somewhere in the bottom of the script the custom public key should be added as extra parameter to this command?

>/dev/stderr echo "Start ssm session to instance ${ec2_instance_id}"
aws ssm start-session \
  --target "${ec2_instance_id}" \
  --document-name 'AWS-StartSSHSession' \
  --parameters "portNumber=${ssh_port}" <-- somewhere here?
qoomon commented 1 year ago

Hi, it should work as is :-)

Can you give some more details e.g.

qoomon commented 1 year ago

have your tried https://github.com/qoomon/aws-ssm-ec2-proxy-command/blob/master/ec2-instance-connect/aws-ssm-ec2-proxy-command.sh ?

ideallical commented 1 year ago

Ah I see now, I had the wrong key algorithm for my custom key. My bad! As when I copied id_rsa and id_rsa.pub to id_rsa2 and id_rsa2.pub and used this:

Host i-* mi-*
  IdentityFile ~/.ssh/id_rsa2
  ProxyCommand ~/.ssh/aws-ssm-ec2-proxy-command.sh %h %r %p ~/.ssh/id_rsa2.pub
  StrictHostKeyChecking no

The connection worked too. So, it was the custom key that caused the issue.

The custom key uses is generated with OPENSSH as opposed to the working id_rsa key which uses RSA.