Gain the convenience of AWS Session Manager's keyless access with the flexibility of traditional SSH configurations.
AWS offers a service called Session Manager, which lets you connect to EC2 instances via WebSocket connection (good for security, since you don't have to open SSH port to public).
However, while the AWS CLI lets you start a session with an instance via Session Manager, it lacks some of the key features that make SSH connections so powerful.
For instance, many tools such as database clients and Docker contexts support SSH, but not aws ssm. Additionally, SSH config allows you to use powerful features like user definitions, aliases, and wildcards.
ssm-ssh-connect bridges this gap by allowing you to use AWS Session Manager as if you were using traditional SSH, without losing any functionality. You can still use your SSH configurations but no longer need to manage SSH keys.
The script:
- automatically retrieves the instance ID using the EC2 instance name (and caches it for future use to speed up subsequent connections)
- pushes your public key to the instance (if it's not already there)
- uses the
session-manager-plugindirectly to establish the session
Single Instance:
Host ec2-instance-name
User ubuntu
ProxyCommand ~/path/to/ssm-ssh-connect <aws-profile-name> %h %r
Multiple Instances (wildcard):
Host prd-* qa-* dev-*
User ubuntu
ProxyCommand ~/path/to/ssm-ssh-connect <aws-profile-name> %h %r
Before you start, make sure you have:
- AWS CLI installed and configured with the appropriate access.
session-manager-plugininstalled.
brew tap scmrus/apps
brew install ssm-ssh-connectDownload the latest release from the releases page, extract the archive, and place the ssm-ssh-connect binary in a directory that is in your PATH.