Connect securely with SSH
When you interact with a deployed environment, you need to guard your connection against unauthorized access. Use Secure Shell (SSH) to provide a secure channel.
You can securely log in to your deployed app to troubleshoot and read logs. And create a tunnel to export data through. And interact with your project through the CLI. All secured through SSH.
To connect to an app securely with SSH, follow two steps.
To authenticate with the CLI:
- Install the Platform.sh CLI.
- In the open browser window, log in with your Platform.sh account credentials. (This webpage is encrypted with HTTPS [HTTP over TLS], making it secure.)
- Authorize the CLI to use your account.
A certificate gets stored in your local SSH configuration. The certificate is automatically cycled every hour for a new certificate as long as your session is active.
If you are inactive for an extended period, your certificate expires and you are asked to login again the next time you use a command that requires authentication.
You are now ready to run CLI commands and to connect to an environment.
To access an app in a given environment via the CLI, run the following command:
platform ssh -p <PROJECT_ID> -e <ENVIRONMENT_NAME> -A <APPLICATION_NAME>
Replace each of
<APPLICATION_NAME> with the values you want to access.
Alternatively, just run
platform ssh and select the values from each list presented to you.
Once you’ve connected, you get a response like this:
___ _ _ __ | _ \ |__ _| |_ / _|___ _ _ _ __ | _/ / _` | _| _/ _ \ '_| ' \ |_| |_\__,_|\__|_| \___/_| |_|_|_| Welcome to Platform. This is environment main of project wk5fqz6qoo123. web@wk5fqz6qoo123-main--php:~$
Now you can interact with the environment as you want.
To open SSH tunnels for all of your services, use the Platform.sh CLI:
$ platform tunnel:open SSH tunnel opened to database at: http://127.0.0.1:30000 Logs are written to: ~/.platformsh/tunnels.log List tunnels with: platform tunnels View tunnel details with: platform tunnel:info Close tunnels with: platform tunnel:close Save encoded tunnel details to the PLATFORM_RELATIONSHIPS variable using: export PLATFORM_RELATIONSHIPS="$(platform tunnel:info --encode)"
Use the returned host (in this case
http://127.0.0.1:30000) for your connection
and fill in the details with the rest of your service credentials.
tunnel:open command connects all relationships defined in your app configuration.
To open only one connection when you have multiple relationships defined, run
Many database applications (such as MySQL Workbench) support establishing their own SSH tunnel. You need to use SSH keys for authentication. Consult the documentation for your application for how to enter SSH credentials.
To get the host and username for connections, run the following command
<ENVIRONMENT_NAME> with appropriate values):
$ platform ssh --pipe -p <PROJECT_ID> -e <ENVIRONMENT_NAME> firstname.lastname@example.org
The host is everything after the
@ and the username is what’s before it.
In this case, the host is
ssh.us.platform.sh and the username is
The host is the same for the entire project, while the username varies by environment.
To connect to a service, fill in the details with the rest of your service credentials.
There are three basic ways to authenticate with Platform.sh:
- Through the CLI
- The fastest and easiest method.
- Supports multifactor authentication.
- Automatically generates new certificates to keep your connection safe.
- Necessary when using the CLI and when your organization has multifactor authentication set up.
- Using SSH keys
- Requires more setup on your part.
- Represents only a single authentication method.
- Requires you to regularly change the keys to maintain security.
- Useful for checking out code as part of an automated process.
- Using API tokens
- Good for letting automation tools use the CLI.
- Requires you to regularly change the tokens to maintain security.