Skip to main content

Managing SSH Connections with ~/.ssh/config

··2 mins·
Arch-Linux Ssh
Makoto Morinaga
Author
Makoto Morinaga
A personal notebook for tech notes, coding, and system experiments.
Table of Contents

Using .ssh/config simplifies SSH connections, eliminating the need to remember and type lengthy commands for each server. By configuring host aliases, specifying user names, defining ports, and managing SSH keys, access to multiple servers becomes more convenient and efficient.

Creating the Config File
#

If SSH key authentication is already set up, the ~/.ssh directory should exist. Otherwise, create it as follows.

Verify if the ~/.ssh directory exists
#

Terminal
ls -la

If ~/.ssh does not exist, create it and set the appropriate permissions:

Terminal
mkdir ~/.ssh
chmod 700 ~/.ssh

Create the ~/.ssh/config file
#

Terminal
touch ~/.ssh/config

Editing ~/.ssh/config
#

Next, add server connection details to ~/.ssh/config. A typical configuration might look like this:

~/.ssh/config
# Server A
Host serverA
    Hostname example.com
    Port 22
    User tanaka
    IdentityFile ~/.ssh/serverA.key

# Server B
Host serverB
    Hostname 192.168.1.10
    Port 50134
    User yamada
    IdentityFile ~/.ssh/serverB.key

# Server C
Host serverC
    Hostname test-server.com
    Port 48912
    User sato

Understanding Key Parameters
#

Parameter Description
Host Alias for the server (used in SSH commands)
HostName Server domain name or IP address
Port SSH port (default: 22)
User SSH login username
IdentityFile Path to the private key (for key authentication)

Additional parameters can be configured as needed, but these are the essential ones.

Connecting to Servers
#

Once the ~/.ssh/config file is set up, connecting to a server is as simple as using the alias defined in the Host field.

To connect to Server A:

Terminal
ssh serverA

To connect to Server B:

Terminal
ssh serverB

To connect to Server C:

Terminal
ssh serverC

Related

SSH Key Authentication Configuration
··2 mins
Arch-Linux Ssh
Basic SSH Configuration
··2 mins
Arch-Linux Ssh
How to install Arch Linux
··3 mins
Arch-Linux