Accessing Services with SSH
Page last updated:
Warning: VMware Tanzu Application Service for VMs (TAS for VMs) v2.9 is no longer supported because it has reached the End of General Support (EOGS) phase as defined by the Support Lifecycle Policy. To stay up to date with the latest software and security updates, upgrade to a supported version.
This page assumes you are using Cloud Foundry Command Line Interface (cf CLI) v6.15.0 or later.
This topic describes how to gain direct command line access to your deployed service instance. For example, you may need access to your database to execute raw SQL commands to edit the schema, import and export data, or debug app data issues.
To establish direct command line access to a service, you deploy a host app and use its SSH and port forwarding features to communicate with the service instance through the app container. The technique outlined below works with TCP services such as MySQL or Redis.
Note: The procedure in this topic requires use of a service key, and not all services support service keys. Some services support credentials through app binding only.
In your terminal window, log in to your deployment with
List the marketplace services installed as product tiles in your Ops Manager deployment. If you need to add the service as a tile, see Adding and Deleting Products. In this example, you create a p-mysql service instance.
$ cf marketplace p-mysql 100mb MySQL databases on demand
Create your service instance. As part of the create-service command, indicate the service name, the service plan, and the name you choose for your service instance.
$ cf create-service p-mysql 100mb MY-DB
To push an app that will act as the host for the SSH tunnel, push any app that will successfully deploy to VMware Tanzu Application Service for VMs.
Note: Your app must be prepared before you push it. See the Pushing an App topic for details on preparing apps for pushing.
- Push your app.
$ cf push YOUR-HOST-APP
- Enable SSH for your app.
$ cf enable-ssh YOUR-HOST-APP
Note: To enable SSH access to your app, SSH access must also be enabled for both the space that contains the app and VMware Tanzu Application Service for VMs. See the App SSH Overview topic for more details.
To establish SSH access to your service instance, you must create a service key that contains critical information for configuring your SSH tunnel.
- Create a service key for your service instance using the cf create-service-key command.
$ cf create-service-key MY-DB EXTERNAL-ACCESS-KEY
- Retrieve your new service key using the cf service-key command.
$ cf service-key MY-DB EXTERNAL-ACCESS-KEY Getting key EXTERNAL-ACCESS-KEY for service instance MY-DB as firstname.lastname@example.org
Configure an SSH tunnel to your service instance using cf ssh. Tailor the example command below with information from your service key.
$ cf ssh -L 63306:us-cdbr-iron-east-01.p-mysql.net:3306 YOUR-HOST-APP
- Use any available local port for port forwarding. For example,
us-cdbr-iron-east-01.p-mysql.netwith the address provided under
hostnamein the service key retrieved above.
3306with the port provided under
YOUR-HOST-APPwith the name of your host app.
After you enter the command, open another terminal window and perform the steps below in Access Your Service Instance.
To establish direct command-line access to your service instance, use the relevant command line tool for that service. This example uses the MySQL command line client to access the p-mysql service instance.
$ mysql -u b5136e448be920 -h 0 -p -D ad_b2fca6t49704585d -P 63306
b5136e448be920with the username provided under
usernamein your service key.
mysqlto connect to your local machine (use
-h 127.0.0.1for Windows).
mysqlto prompt for a password. When prompted, use the password provided under
passwordin your service key.
ad_b2fca6t49704585dwith the database name provided under
namein your service key.
mysqlto connect on port