SSH command shortcuts are aliases, configuration file entries, and shell tricks that reduce the amount of typing needed to connect to remote servers and run frequent commands. You can create persistent shortcuts for hosts, keys, and options in ~/.ssh/config, and shell-level aliases for entire commands. This article explains the most useful shortcuts, how they work, and how to set them up safely.
Why Use SSH Shortcuts
Typing a full SSH command like ssh -i ~/.ssh/aws-key.pem -p 2222 ubuntu@192.168.1.50 every time is error-prone and slow. Shortcuts save time, reduce typos, and make complex connections repeatable. They also let you standardize options like compression, port forwarding, or identity files across multiple machines. For anyone who manages more than a couple of servers, the ~/.ssh/config file is the single most effective shortcut tool.
The ~/.ssh/config File
OpenSSH reads ~/.ssh/config (and system-wide /etc/ssh/ssh_config) before making a connection. Each block starts with Host, followed by an alias you choose, then indented options. When you type ssh myalias, SSH applies all the settings in that block.
Example config:
Host web
HostName 192.168.1.50
User ubuntu
Port 2222
IdentityFile ~/.ssh/aws-key.pem
Compression yes
Now ssh web connects with all those options. You can also use wildcards: Host *.example.com applies settings to any host in that domain. The first matching block wins, so put more specific entries first.
Common Config Shortcuts
Beyond basic connection details, the config file supports many options that act as shortcuts:
- ForwardAgent — reuse your local SSH keys on the remote server (
ForwardAgent yes). - LocalForward / RemoteForward — set up port forwarding automatically on connect.
- ProxyJump — hop through a bastion host:
ProxyJump jump-server. - ServerAliveInterval — keep connections alive with keepalive packets.
- RequestTTY — force a pseudo-terminal for interactive sessions.
- StrictHostKeyChecking — set to
accept-newto auto-accept new host keys (use with caution).
Each option is documented in man ssh_config. Using them in config files means you don’t have to remember the command-line flags.
Shell Aliases and Functions
For commands that aren’t pure SSH (like copying files or running a command on multiple servers), shell aliases work well. In ~/.bashrc or ~/.zshrc:
alias sshweb='ssh web' alias uptime-all='for h in web db cache; do echo "$h:"; ssh $h uptime; done'
Functions allow more logic. For example, a function to SSH to a server and immediately change to a project directory:
dev() { ssh dev-server "cd /var/www && exec bash"; }
Aliases are expanded by your shell before the command runs, so they can also include SSH options: alias sshtunnel='ssh -N -L 8080:localhost:80 web'.
SSH Key Shortcuts
Using SSH keys instead of passwords is itself a shortcut. Once you copy your public key to the server with ssh-copy-id user@host, you can log in without typing a password. To avoid typing a passphrase every time, use ssh-agent and ssh-add. Add this to your shell startup:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
Then your key is unlocked for the session. For multiple keys, the config file’s IdentityFile option tells SSH which key to use for which host, so you don’t have to specify -i each time.
Command-Line Shortcuts
Even without config files, SSH has built-in shortcuts:
ssh host command— run a single command on the remote host and exit.ssh -t host command— force a pseudo-terminal for commands that need one (liketop).ssh -N -L 8080:localhost:80 host— create a tunnel without executing a remote command.scp host:file .— copy a file from a host defined in config.ssh host -o Option=Value— override any config option for one command.
Tab completion also works for hostnames if you set Host entries in config, depending on your shell.
Common Mistakes and Safety
Shortcuts can introduce security risks if misconfigured. Avoid setting StrictHostKeyChecking no globally — it makes you vulnerable to man-in-the-middle attacks. Instead, use accept-new only for hosts you trust. Also, be careful with ForwardAgent yes; it lets the remote server use your local keys, so only enable it for hosts you fully control.
Another common mistake is forgetting that config file options apply to all connections that match the Host pattern. A broad wildcard like Host * with an IdentityFile can break connections to hosts that expect a different key. Always test a new config with ssh -v host to see which options are being applied.
Permissions matter: SSH will ignore your config file if it’s world-writable. Set chmod 600 ~/.ssh/config and chmod 700 ~/.ssh.
Frequently Asked Questions
How do I create an SSH shortcut in Windows?
Windows 10 and 11 include OpenSSH, so the same ~/.ssh/config file works in PowerShell or CMD. Create the file with notepad $HOME\.ssh\config and add your host blocks. You can also use ssh.exe with aliases in PowerShell profiles.
Can I use SSH shortcuts for SCP and SFTP?
Yes. Both scp and sftp use the same config file. If you have a Host web entry, you can run scp file web:/path or sftp web and the settings (user, port, key) are applied automatically.
What is the difference between an alias and a config entry?
A config entry defines connection parameters for a hostname alias; it’s interpreted by SSH itself. A shell alias is a text substitution done by your shell before the command runs. Config entries are more powerful because they can include wildcards and are used by all SSH tools (scp, sftp, rsync over ssh).
How do I override a config option for one command?
Use the -o flag: ssh -o Port=2222 web. This overrides the config value for that single connection. You can also use -F /path/to/other/config to use a different config file entirely.
Why is my SSH config file not being read?
Check permissions — the file must be readable only by you (chmod 600). Also verify the path: SSH looks at ~/.ssh/config by default. If you’re using a custom path, specify it with -F. Finally, ensure the Host line matches the alias you type exactly (case-sensitive).
Is it safe to use SSH config shortcuts for production servers?
Yes, if you follow security best practices: use key-based authentication, keep your private keys protected, avoid disabling host key checking, and limit agent forwarding to trusted hosts. Config shortcuts are just a convenience layer over standard SSH; they don’t weaken the protocol itself.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Backup Not Enough Space? Fix It Now200.00 GB
- Approximate Match Lookup: Conditional Formatting
- GST on Delivery Charges in India: E-Commerce Rules
- NFC Reader on Your Phone: 9 Things You’re Not Doing
- Smart TV DNS Settings: Why They Change & How to Fix
- RabbitMQ Hosting for Startups: Managed vs Self-Hosted