Skip to content

Commit

Permalink
docs(readme): add details to the documentation on how to setup a ssh …
Browse files Browse the repository at this point in the history
…tunnel connection
  • Loading branch information
danvergara committed Jan 2, 2025
1 parent 2ba34f7 commit 1201764
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ run-mysql-url: build
## run-mysql-url-ssh: Runs the app passing the url as parameter through a ssh tunnel providing the url as parameter
run-mysql-url-ssh: build
./dblab --url "mysql://myuser:5@klkbN#ABC@mysql+tcp(mysql:3306)/mydb" --driver mysql --ssh-host localhost --ssh-port 2222 --ssh-user root --ssh-pass root
# ./dblab --host mysql --user myuser --db mydb --pass 5@klkbN#ABC --ssl enable --port 3306 --driver mysql --limit 50 --ssh-host localhost --ssh-port 2222 --ssh-user root --ssh-pass root

.PHONY: run-config
## run-config: Runs the client using the config file.
Expand Down
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ __Interactive client for PostgreSQL, MySQL, SQLite3, Oracle and SQL Server.__
- [Automated installation/update](#automated-installationupdate)
- [Help Command](#help)
- [Usage](#usage)
- [SSH Tunnel](#ssh-tunnel)
- [Configuration](#configuration)
- [Navigation](#navigation)
- [Key Bindings](#key-bindings)
Expand Down Expand Up @@ -103,6 +104,12 @@ Flags:
--port string Server port
--schema string Database schema (postgres only)
--socket string Path to a Unix socket file
--ssh-host string SSH Server Hostname/IP
--ssh-key string File with private key for SSH authentication
--ssh-key-pass string Supports connections with protected private keys with passphrase
--ssh-pass string SSH Password (Empty string for no password)
--ssh-port string SSH Port
--ssh-user string SSH User
--ssl string SSL mode
--ssl-verify string [enable|disable] or [true|false] enable ssl verify for the server
--sslcert string This parameter specifies the file name of the client SSL certificate, replacing the default ~/.postgresql/postgresql.crt
Expand Down Expand Up @@ -170,6 +177,59 @@ Now, it is possible to ensure SSL connections with `PostgreSQL` databases. SSL r
dblab --host db-postgresql-nyc3-56456-do-user-foo-0.fake.db.ondigitalocean.com --user myuser --db users --pass password --schema myschema --port 5432 --driver postgres --limit 50 --ssl require --sslrootcert ~/Downloads/foo.crt
```

### SSH Tunnel

Now, it's possible to connect to Postgres or MySQL (more to come later) databases on a server via SSH using password or a ssh key files.

To do so, 6 new flags has been added to the dblab command:

| Flag | Description |
|----------------------|-------------------------------------------------------------------|
| --ssh-host | SSH Server Hostname/IP |
| --ssh-port | SSH Port |
| --ssh-user | SSH User |
| --ssh-pass | SSH Password (Empty string for no password) |
| --ssh-key | File with private key for SSH authentication |
| --ssh-key-pass | Passphrase for protected private key files |

#### Examples

Postgres connection via ssh tunnel using password:

```{ .sh .copy }
dblab --host localhost --user postgres --pass password --schema public --ssl disable --port 5432 --driver postgres --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root
```

Postgres connection via ssh tunnel using ssh private key file:

```{ .sh .copy }
dblab --host localhost --user postgres --pass password --schema public --ssl disable --port 5432 --driver postgres --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-key my_ssh_key --ssh-key-pass password
```

Postgres connection using the url parameter via ssh tunnel using password:

```{ .sh .copy }
dblab --url postgres://postgres:password@localhost:5432/users?sslmode=disable --schema public --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root
```

MySQL connection via ssh tunnel using password:

```{ .sh .copy }
dblab --host localhost --user myuser --db mydb --pass 5@klkbN#ABC --ssl enable --port 3306 --driver mysql --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root
```

MySQL connection via ssh tunnel using ssh private key file:

```{ .sh .copy }
dblab --host localhost --user postgres --pass password --ssl enable --port 3306 --driver mysql --limit 50 --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-key my_ssh_key --ssh-key-pass passphrase
```

MySQL connection using the url parameter via ssh tunnel using password:

```{ .sh .copy }
dblab --url "mysql://myuser:5@klkbN#ABC@mysql+tcp(localhost:3306)/mydb" --driver mysql --ssh-host example.com --ssh-port 22 --ssh-user root --ssh-pass root
```

### Configuration

Enter previous flags every time is tedious, so `dblab` provides a couple of flags to help with it: `--config` and `--cfg-name`.
Expand Down Expand Up @@ -236,6 +296,18 @@ database:
db: "msdb"
password: "5@klkbN#ABC"
user: "SA"
- name: "ssh-tunnel"
host: "localhost"
port: 5432
db: "users"
password: "password"
user: "postgres"
schema: "public"
driver: "postgres"
ssh-host: "example.com"
ssh-port: 22
ssh-user: "ssh-user"
ssh-pass: "password"
# should be greater than 0, otherwise the app will error out
limit: 50
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
sslkey string
sslpassword string
sslrootcert string
// SSH.
// SSH Tunnel.
sshHost string
sshPort string
sshUser string
Expand Down

0 comments on commit 1201764

Please sign in to comment.