logbook · entry 001
Getting into EC2 without SSH: a small CLI around AWS Session Manager
If you run EC2 instances, you've probably managed SSH keys, a bastion host, and a security group with port 22 open "just for us". AWS Systems Manager Session Manager gets rid of all three: the SSM Agent on the instance connects out to AWS, you authenticate with IAM, and you get a shell with no open inbound ports and no keys to rotate.
The catch is the command you type every time:
aws ssm start-session --target i-0a1b2c3d4e5f67890 --region us-east-1 --profile my-sso-profile
Instance IDs aren't memorable, your SSO session expires halfway through the day, and there's no scp. So I wrote ssm-connect, a small open-source CLI that makes Session Manager feel like SSH.
What it does
Names instead of instance IDs. Give instances short aliases, and optionally group them:
ssm-connect -a web-1 i-0a1b2c3d4e5f67890 web
ssm-connect -a web-2 i-0f9e8d7c6b5a43210 web
Then connect by name, pick from a group, or run it bare for a fuzzy-search picker sorted by what you use most:
ssm-connect web-1 # straight in
ssm-connect web # choose within the "web" group
ssm-connect # search everything
SSO that looks after itself. The first run walks you through aws configure sso. After that, every command checks your session and runs aws sso login for you when it has expired.
File copy with scp syntax.
ssm-connect --scp ./config.yaml web-1:~/
ssm-connect --scp web-1:/var/log/app.log ./
The rest: bash and zsh completion for flags, aliases and alias: paths; a daily update check; and ssm-connect --update to upgrade in place.
How --scp works without SSH
Session Manager has no file-transfer channel, so --scp goes through an S3 bucket you choose and uses SSM Run Command to do the copy on the instance:
- Upload: your laptop puts the file in S3. An
AWS-RunShellScriptcommand on the instance pulls it down. The staged copy is then deleted. - Download: the same thing in reverse.
A few details matter here, because the command on the instance runs as root:
- Integrity: every file is SHA-256 checksummed where it starts and checked where it lands. An upload is written beside its destination and only renamed into place once the checksum matches.
- Unguessable staging: staged objects get random 128-bit names and are removed however the transfer ends, including when it fails.
- No shell injection: remote paths and settings are validated before they go anywhere near the remote command.
Security choices
- No inbound ports, no SSH keys: access is entirely IAM, and every session is recorded in CloudTrail.
- Signed updates: releases are signed with an SSH key (
ssh-keygen -Y sign).--updatedownloads from the release's git tag and refuses any file whose signature doesn't verify against the public key built into the script. A compromised repository can't push code onto your machine. - Nothing account-specific built in: your region comes from your AWS profile, and the bucket and instance user are set with
ssm-connect --config.
Heads-up: Session Manager changes on 28 May 2027
ssm-connect checks your plugin version when you connect. If it's too old, it offers to update it, or you can run ssm-connect --update-plugin. The IAM change is yours to make in your permission sets or policies, so it's worth doing now rather than finding out on the day.
Try it
You need the AWS CLI v2, session-manager-plugin, fzf and jq. The installer sets these up for you.
# Linux
curl -fsSL https://raw.githubusercontent.com/muhammadsemeer/ssm-connect/master/install.sh | sudo bash
# macOS
curl -fsSL https://raw.githubusercontent.com/muhammadsemeer/ssm-connect/master/install.sh | bash
Then:
ssm-connect # first run sets up AWS SSO
ssm-connect --config # view settings
The README's AWS setup section lists exactly which IAM permissions the instances and your sign-in role need.
Limits and what's next
- It runs on Linux and macOS, not Windows.
--scpcopies single files, through an S3 bucket you provide.- The instance user defaults to
ubuntu; change it withssm-connect --config scp-user ec2-user.
The code is MIT-licensed at github.com/muhammadsemeer/ssm-connect. Issues and pull requests are welcome.