Home UbuntuSSH Config File: 10 Time-Saving Tricks for Linux Server Admins

SSH Config File: 10 Time-Saving Tricks for Linux Server Admins

by Knowledge Base Linux
Technical illustration of an SSH config file speeding up Linux server administration

Why the SSH Config File Belongs in Every Admin’s Toolkit

If you manage Linux servers, you probably type commands like ssh -i ~/.ssh/prod_key.pem -p 2222 [email protected] dozens of times a day. It is slow, error-prone, and impossible to remember across a fleet of machines. The ssh config file solves this problem completely: it lets you store per-host connection settings once, then connect with a short alias like ssh web1. This single file — ~/.ssh/config on your workstation — is one of the highest-leverage productivity tools a server admin can learn. Below are ten practical tricks that turn repetitive connection chores into one-word commands.

Example SSH config file entries showing host aliases, ProxyJump and port forwarding

SSH Config File Basics: Location and Permissions

Before the tricks, two fundamentals. The user-level ssh config file lives at ~/.ssh/config; a system-wide one lives at /etc/ssh/ssh_config. OpenSSH reads the user file first, then the system file, and the first value obtained for any option wins — which means your personal file overrides the system defaults.

Permissions matter: SSH will silently ignore a config file that is readable by others. Set them once and forget them:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config

You should already have an SSH key pair generated. If not, follow our guide on how to generate SSH keys on Linux first — nearly every trick below assumes key-based authentication.

10 SSH Config File Tricks That Save Real Time

Trick 1: Create short aliases for your servers

The simplest and most-used trick. Instead of memorizing IPs, give each server a nickname:

Host web1
    HostName 203.0.113.10
    User deploy

Host db1
    HostName 203.0.113.20
    User postgres

Now ssh web1 connects as [email protected]. Aliases also work with scp, rsync, and sftp: scp backup.tar.gz web1:/tmp/. When a server’s IP changes, you update one line in the ssh config file instead of every script and shell history entry.

Trick 2: Bake in the port and other defaults per host

If you run SSH on a non-standard port — a common hardening step covered in our article on how to change the SSH port on Linux — store it in your ssh config file per host so you never type -p again:

Host web1
    HostName 203.0.113.10
    User deploy
    Port 2222

Trick 3: Configure whole fleets with wildcards

Patterns with * and ? let one block cover many hosts. Put specific hosts first and general patterns later, because the first obtained value wins:

Host db1
    HostName 203.0.113.20
    User postgres

Host 203.0.113.*
    User deploy
    Port 2222

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

Here every host in the 203.0.113.0/24 range gets the deploy user and port 2222, while db1 keeps its own settings. The final Host * block applies defaults everywhere.

Trick 4: Jump through bastion hosts with ProxyJump

Reaching private servers behind a bastion used to mean nested SSH sessions or long ProxyCommand strings. ProxyJump reduces it to one line:

Host bastion
    HostName 203.0.113.5
    User admin

Host app-private
    HostName 10.0.1.15
    User deploy
    ProxyJump bastion

ssh app-private now hops transparently through the bastion. You can even chain jumps with a comma-separated list: ProxyJump bastion,dmz-jump. File copies work too: scp app-private:/var/log/app.log .

Trick 5: Set up port forwarding once, reuse forever

Need regular access to a database console or internal dashboard? Define the tunnel in the ssh config file instead of retyping -L flags:

Host db-tunnel
    HostName 203.0.113.20
    User deploy
    LocalForward 5433 localhost:5432

Host socks-proxy
    HostName 203.0.113.5
    User admin
    DynamicForward 1080

Connecting to db-tunnel always forwards local port 5433 to the remote PostgreSQL port, and socks-proxy gives you a SOCKS proxy on port 1080 for browsing internal resources securely.

Trick 6: Stop dropped connections with keepalives

Idle sessions killed by NAT timeouts or firewalls are a daily annoyance. Two options fix it client-side:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

This sends a keepalive packet every 60 seconds; if three in a row go unanswered, the client disconnects cleanly instead of hanging forever. Note this is different from TCPKeepAlive, which is less reliable through NAT.

Trick 7: Reuse connections with multiplexing

Opening a second session to the same server should not require a second handshake. Connection multiplexing keeps one master connection and reuses it:

Host *
    ControlMaster auto
    ControlPath ~/.ssh/sockets/%r@%h-%p
    ControlPersist 10m

Create ~/.ssh/sockets first. Once these three lines are in your ssh config file, subsequent ssh, scp, and rsync commands to the same host connect instantly — no repeated password or key prompts — and the master connection lingers for 10 minutes after you log out. The tokens %r, %h, and %p expand to remote user, hostname, and port, keeping socket paths unique.

Trick 8: Pin the right key with IdentityFile and IdentitiesOnly

Admins juggling several keys often hit “too many authentication failures” because SSH offers every key in the agent. Pin keys per host and stop the guessing:

Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    IdentitiesOnly yes

Host *
    AddKeysToAgent yes

IdentitiesOnly yes tells SSH to offer only the configured key. AddKeysToAgent yes automatically loads keys into ssh-agent on first use, so passphrases are asked once per login session.

Trick 9: Apply conditional settings with Match blocks

Match restricts the following options to connections meeting specific criteria — by host, user, or even the result of a command:

Match host *.staging.example.com
    User staging-deploy
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null

Match exec "test -d /run/.containerenv"
    ForwardAgent no

The first block relaxes host-key checking for throwaway staging machines. The second uses exec to detect when you are SSHing from inside a container and disables agent forwarding there. Match criteria confirmed in the ssh_config(5) man page include canonical, final, exec, host, originalhost, user, and localuser.

Trick 10: Split and organize with Include

A config with fifty hosts gets unwieldy. Split it into topic files and include them:

Include ~/.ssh/config.d/*.conf

Keep ~/.ssh/config.d/work.conf, personal.conf, and clients.conf separate. This also makes it easy to share a client-specific snippet of your ssh config file with teammates or version-control your own. For extra safety on new servers, add VisualHostKey yes to your global block — SSH will print an ASCII-art fingerprint of the host key at login, making man-in-the-middle tampering visually obvious.

Troubleshooting Your SSH Config File

“Bad configuration option” errors. You used an option name that does not exist or misspelled one. Verify names against man ssh_config or the OpenSSH ssh_config documentation. Remember the file is case-insensitive for keywords but sensitive about spelling.

Settings seem ignored. Check two things: file permissions (must be 600, directory 700) and block order — the first obtained value wins, so a Host * block placed above a specific host will shadow it. Move general blocks to the bottom.

Seeing the effective configuration. Run ssh -G web1 to print every option SSH will actually use for that alias — the fastest way to confirm which block won. Add -v to a real connection (ssh -v web1) to watch which config files are read and which key is offered.

Multiplexing socket errors. If you see “too long” or permission errors, the ControlPath directory does not exist or the expanded path exceeds the Unix socket length limit. Create ~/.ssh/sockets and keep the pattern short.

Conclusion

The ssh config file turns long, fragile connection commands into short, memorable aliases — and then goes further with bastion jumps, persistent tunnels, keepalives, connection reuse, and conditional logic. Start with aliases and per-host users and ports today; add wildcards, ProxyJump, and multiplexing as your fleet grows. Ten minutes of configuration will save you hours every month, and your shell history will thank you.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.