SSh Hosts and Private Keys
You work with many remote networks on a daily basis as a server administrator. Throughout your job, you may need to SSH into systems several times. You can access several remote Linux servers with a password, and you can even access them with a private key. As a result, managing all of them might be more typical.
Table of Contents
This article will show you the best way to manage SSH Hosts and Private Keys.

Syntax of the Configuration File:
Multiple ssh hosts may be defined in the /.ssh/config
file. Use your favorite editor, such as vi, vim, or nano,
to edit the configuration file.
$ vi ~/.ssh/config
Host
HostName
IdentityFile
User
Port
LocalForward
1. Configure the First SSH Host
For instance, our first SSH host is running a PHP development web server with the following details: nickname php-web1,
user root, port 22,
and password access. In the configuration file, add the following content.
Host php-web1
HostName 192.168.1.100
User root
$ ssh php-web1
2. Configure a second SSH host
On default port 22,
our second host server (php-web2)
is accessible via ssh key-pair with user root. In the configuration file, add the following content.
Host php-web2
HostName 192.168.1.101
IdentityFile ~/.ssh/php-web2.pem
User root
Now try SSH with the command below.
$ ssh php-web2
3. Add a third SSH host server
Our third ssh host server (php-db1)
is accessible via key-pair with user ubuntu on port 2222.
In the configuration file, add the following content.
Host php-db1
HostName 192.168.1.110
Port 2222
IdentityFile ~/.ssh/php-db1.pem
User ubuntu
Now try SSH with the command below.
$ ssh php-db1
4. Use SSH to set up forwarding
In this setup, we must forward port 3306
from our local system to remote servers (php-db1)
. In the configuration file, add the following content.
Host php-db1-mysql-tunnel
HostName 192.168.1.110
Port 2222
IdentityFile ~/.ssh/php-db1.pem
LocalForward 3306 127.0.0.1:3306
$ ssh php-db1-mysql-tunnel
File with Final Configuration
/.ssh/config.
Host php-web1
HostName 192.168.1.100
User root
Host php-web2
HostName 192.168.1.101
IdentityFile ~/.ssh/php-web2.pem
User root
Host php-db1
HostName 192.168.1.110
Port 2222
IdentityFile ~/.ssh/php-db1.pem
User ubuntu
Host php-db1-mysql-tunnel
HostName 192.168.1.110
Port 2222
IdentityFile ~/.ssh/php-db1.pem
LocalForward 3306 127.0.0.1:3306
Saad Shafqat
Related posts
New Articles
Getting Around: 9 Top Keyboard Shortcuts for Mac
As easy to use as Macs are, there’s always room for improvement in the user-friendly department. Case in point: Mac…