I Stopped Typing Long SSH Commands — My Terminal Now Understands db dev
You know that small thing at work that isn’t really a problem… but somehow annoys you every single day?
For me, it was SSH commands. 😅
At work, I regularly connect to different environments — DEV, STAGE, and sometimes PROD — for databases, Redis, and other services.
And every time, I had to type something like:
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 \
-L 5434:db.dev.company.local:5432 \
your.username@bastion.dev.company.comThen came the legendary ↑ arrow.
It worked. But it doesn’t feel right.
Luckily, I have a genius colleague and a good friend who introduced me to a much simpler way of handling this. he showed me the trick, I tried it, and within a few minutes I was thinking,
Why am I typing these long SSH commands manually when the terminal can do it for me?
So, with a little help from my friend, I set up my own little terminal shortcuts — and honestly, it has made my everyday workflow so much easier.
Connect with him on LinkedIn and check out his work!
Enter: db dev
I created a small shell function that lets me simply run:
db devor:
db stageor:
db prodThe long SSH command? Gone.
Step 1: Create a custom commands file
Instead of putting everything directly into .zshrc, I created a separate file:
touch ~/.my-commands.shThen:
nano ~/.my-commands.shStep 2: Create the db command
Inside ~/.my-commands.sh, I added:
db() {
case "$1" in
dev)
echo "Connecting to DB DEV..."
ssh -o ServerAliveInterval=60 \
-o ServerAliveCountMax=3 \
-L 5434:db.dev.company.local:5432 \
your.username@bastion.dev.company.com
;;
stage)
echo "Connecting to DB STAGE..."
ssh -o ServerAliveInterval=60 \
-o ServerAliveCountMax=3 \
-L 5434:db.stage.company.local:5432 \
your.username@bastion.stage.company.com
;;
prod)
echo "Connecting to DB PROD..."
ssh -o ServerAliveInterval=60 \
-o ServerAliveCountMax=3 \
-L 5434:db.company.local:5432 \
your.username@bastion.company.com
;;
*)
echo "Usage: db {dev|stage|prod}"
;;
esac
}Step 3: Tell Zsh about the file
I’m using Zsh, so I added this to my ~/.zshrc:
source ~/.my-commands.shThen reload:
source ~/.zshrcThat’s it.
Get Subhadipta Nayak 👨💻’s stories in your inbox
Join Medium for free to get updates from this writer.
Now:
db devstarts my DEV connection.
That tiny reduction in friction is actually pretty nice when you’re doing it several times every day.
The takeaway
Sometimes developer productivity isn’t about learning another huge tool.
Sometimes it’s just asking:
“Why am I doing this manually every day?”
If you type the same long command repeatedly, there’s a good chance your shell can turn it into something much simpler.
For me, going from:
ssh -o ServerAliveInterval=60 ...to:
db devwas a tiny change.
But after using it every day, I don’t want to go back. 😄
So if you have a long command that you keep typing at work, stop typing it. Turn it into a command.
Your future self will thank you.







