Skip to content

Database Connection Management

deepsky edited this page Feb 28, 2014 · 1 revision
HOW TO SETUP PUBLIC KEY AUTH FOR CONNECTION VIA SSH TUNNEL

For example you want to connect to the database on DB-ONE host which is not accessible directly from your host (SMITH).
The standard way to resolve this issue is to use SSH tunnel via an intermediate or "jump" host which can access DB-ONE host.
But you want to have database connection procedure to be as simple as possible without having to enter password on SSH authentication.
To have this solved you have to use Public Key Authentication and below you can find an example how
to generate Public/Private Key pair and setup Public Key Auth on the host jump.

#1. Create Public/Private Key pair<br>
$ ssh-keygen -t rsa<br>
Generating public/private rsa key pair.<br>
Enter file in which to save the key (/home/user/.ssh/id_rsa): <use default or enter new location><br>
Enter passphrase (empty to have no passphrase):<br>
Enter same passphrase again:<br>
Your identification has been saved in /home/username/.ssh/id_rsa.<br>
Your public key has been saved in /home/username/.ssh/id_rsa.pub.<br>
The key fingerprint is:<br>
ab:f9:23:a6:f0:db:ce:64:59:dd:98:b9:be:7c:57:6f username@smith<br>

#2. Create .ssh folder on jump server, if it already exists, skip this step<br>
ssh b@jump mkdir -p .ssh<br>
b@jump's password:<br>

#3. Append username's new public key to b@jump:.ssh/authorized_keys<br>
cat .ssh/id_rsa.pub | ssh b@jump 'cat >> .ssh/authorized_keys'<br>

#4. Specify private key (/home/username/.ssh/id_rsa) in the Connection Setting dialog to enable
Public Key Authentication for connection via SSH tunnel.<br>

See more details on setting up Public Key Auth here: http://www.linuxproblem.org/art_9.html

Clone this wiki locally