Simplify SSH Connections with Ubuntu Config File
Managing multiple remote servers via SSH can quickly become tedious
when you have to remember different IP addresses, usernames, custom
ports, and unique private keys for each machine. This article explains
how the local user SSH configuration file (~/.ssh/config)
on an Ubuntu Linux client simplifies this process, allowing you to
replace long, complex SSH commands with short, memorable aliases.
The Problem: Standard SSH Connections
When connecting to a remote server without a configuration file, you must specify all connection parameters manually in the terminal. A typical command might look like this:
ssh -i ~/.ssh/custom_key -p 22022 username@192.168.1.50Typing this out every time is prone to errors, especially when managing dozens of servers with varying credentials.
The Solution: The SSH Config File
The local SSH configuration file acts as a translation directory for your SSH client. By defining your server details once in this file, the SSH client automatically applies the correct parameters when you attempt to connect.
The configuration file is stored in your user directory at:
~/.ssh/config
Setting Up the Config File
If the file does not exist on your Ubuntu client, you can create it and set the correct permissions with the following commands:
touch ~/.ssh/config
chmod 600 ~/.ssh/configConfiguration Syntax Example
Open the file in a text editor like Nano
(nano ~/.ssh/config) and define your servers using the
following structure:
Host webserver
HostName 192.168.1.50
User username
Port 22022
IdentityFile ~/.ssh/custom_key
Host databaseserver
HostName db.example.com
User admin
IdentityFile ~/.ssh/id_rsa
How This Simplifies Your Workflow
Once configured, the SSH client handles the heavy lifting behind the scenes.
1. Shortened Commands
Instead of typing the full IP, port, and key path, you can connect
using only the alias defined in the Host line:
ssh webserver2. Streamlined File Transfers
The alias configuration also applies to other tools that rely on SSH,
such as scp and rsync. For example,
transferring a file becomes much simpler:
scp document.txt webserver:/var/www/html/3. Wildcard and Global Configurations
You can set global parameters for all hosts or groups of hosts using
wildcards (*). This eliminates the need to repeat
configuration lines for every server:
Host *.example.com
User admin
Port 2222
Host *
Compression yes
ServerAliveInterval 60
By leveraging the local SSH configuration file on Ubuntu, you eliminate the cognitive load of memorizing server details, reduce typing errors, and significantly speed up your daily administrative tasks.