Etiqueta: ssh

SSH tunnel

SSH is a great tool to open remote secure shells, this is widely used but a less know option SSH has is that can be used to acces the network of the remote server.

Usually if you work with VPS , by security you only open the ports essential, but imagine that you have to access a management web of the server that only can be accessed from loacalhost.

You can solve this with ssh tunneling

ssh remoteserver -L 8090:localhost:8080

This can be a bit confusing but let me explain the parts:

  • ssh remoteserver : Usual ssh remote shell
  • -L : Specifies port forwarding
  • 8089: Local port, the port where your browser will connect
  • localhost: Remote connection, ip address where the remote ssh will connect
  • 8080: Remote port where the remote ssh will connect

If you try this you will notice that it opens a remote shell, if you don’t need it you can additionally add the -N argument to avoid it

DBeaver

DBeaver (https://dbeaver.io/download/) is a great gui tool that allows us to connect and query multiple databases (Postgres,Mysql,Oracle…) from multiple operating systems. DBeaver is free but also has a paid version with extra functionalities

Configuring a connection to Postgres

You can create a new connection going to “File>New>DBeaver>Database connection” or clicking on the socket icon. After this we will see a screen like this:

Screen to select the connection driver

After this we can fill the connection information

My recommendation is to test the connection before finishing

Trick

If you want to use this connection to access different databases you can specify this on the PostgreSQL tab, and enable the “Show all databases” option

You can configure more databases like MySQL or Oracle

Configuring a connection with a SSH tunnel

A cool feature of DBeaver is that it can connect to a database that is on a remote machine without having to expose the service to the whole Internet.

To do this you can go to the tab of “SSH” and configure the

Once you fill the host,user and password you can test the connection and finish

Other functionalities

Viewing the database schema

With DBeaver you can see the database diagram using this button or you can see the relations of a single table.

The result is something like this:

Viewing gis data

A cool feature of DBeaver is the integration with Postgis, so if you double click over a geometry field you will be able to preview the feature in a map

Tmux

Tmux is a terminal multiplexer. This is the kind of tools where you don’t know that you need. This tool is useful when you may work with remote servers via terminal.

This allows you to:

  • Have multiple terminals on the same connection
  • Be able to disconnect from the terminal without terminating the running
  • Share terminal with other users

How to install

To install tmux you can run this command:

apt-get install tmux

How to use:

You can create a new tmux session this command:

tmux

You can attach to an existing running session :

tmux attach 

or a shorter version:

tmux a

Once you are on a tmux session you have the following shortcuts:

  • Control+b+c: Open a new window.
  • Control+b+d: Detach of a tmux session.
  • Control+n: Move to the next window.
  • Control+p: Move to the previous window.
  • Control+b+number: Move to the number window.
  • Control+b+”: Slit the window horizontally.
  • Control+b+%: Split the window vertically.
  • Control+b+$: Rename session
  • Control+b+s: Change the session

Share a tmux session

You can share a tmux session with another ssh session with the same user via ssh.

Also if you can’t share the ssh connection you can use tmate.

You can install tmate with this command:

apt-get install tmate

Once tmate is installed you can run the command:

tmate

This will give you a list of ways to share the tmux session

© 2024 Another dev

Tema de Anders NorenAmunt ↑