General
There are two primary methods to access databases managed by Teleport using the command-line
- The Teleport Connect Client
- The
tshCLI tool - PostgreSQL CLI tool (psql)
Both methods will create a port forward from your local machine to the database server through the Teleport proxy. This means that you will need a working SSH connection to the Teleport proxy in order to access the database.
Prerequisites
- Teleport Connect or
tshCLI tool installed. Refer to the Client Installation guide for installation instructions. - A valid Teleport user account with access to the desired database and logged in using either Teleport Connect or
tsh login.
Using Teleport Connect
Launch Teleport Connect
Open the Teleport Connect application from your applications menu or desktop shortcut.
Chose desired database connection
In the overview page, locate the database you want to connect to and click on the Connect button next to it and select the desired PostgreSQL User. You can filter for Self-hosted PostgreSQL databases using the search bar at the top.
Establish connection
Enter a free port on your local machine to forward the database connection to and specify a database name if needed. Click on the Connect button to establish the connection. Teleport Connect will set up a port forward from your local machine to the database server through the Teleport proxy.
Access the database
Use psql or any PostgreSQL client to connect to the database using localhost and the port you specified in the previous step.
psql -h localhost -p <local-port> -U <db-username>Using tsh CLI
Make sure you are signed in to Teleport
Use the tsh status command to verify that you are logged in to your Teleport cluster:
tsh statusList available databases
Use the tsh db ls command to list all available databases you have access to:
tsh db lsConnect to the database
Use the tsh db login and tsh db connect commands to connect to the desired database:
tsh db login [--db-user=<user>] <servername>
tsh db connect [--db-user=<user>] <servername> --local-port=<local-port>