Environment variables
This page explains how to configure, pass, and verify environment variables in remote SSH sessions, including server-side AcceptEnv rules.
Overview
Environment variables let you pass KEY=VALUE pairs to the remote shell as part of establishing an SSH connection. Termius sends them automatically on connect, using the same mechanism as OpenSSH's SendEnv client-side directive.
Example
LANG=en_US.UTF-8
APP_ENV=stagingAccepted environment variables
To allow specific environment variables, list them after AcceptEnv keyword in the server's sshd_config (typically /etc/ssh/sshd_config). The AcceptEnv directives specify which client-sent variables are copied into the session's environment.
You can list one or more variable names after AcceptEnv keyword, and each name may contain the wildcards * and ? to include groups of values. Multiple names can be separated by spaces on one line, or split across several AcceptEnv lines.
Example
# sshd_config on the remote server
AcceptEnv LANG LC_* APP_ENVWith this configuration, only LANG, variables matching LC_* (e.g. LC_TIME, LC_ALL), and APP_ENV are accepted. Any other variable sent by Termius but not listed in AcceptEnv is silently dropped by sshd.
Set an environment variables in Termius
Open the Host details, scroll to the credential section and click
Show more
Click
Environment Variable
Click
Add a variable, add your variable asVARIABLE(KEY)=VALUE, thenSave
To confirm the variable is set correctly, you can
echoit once connected. If it prints the expected value, the variable is set. If it's empty, double-check that the variable name matches theAcceptEnvpattern insshd_config, see Accepted environment variables above
Pro tip
Several hosts may run similar workloads with different service names. For example, some hosts may use nginx, while others use gunicorn. Let's assume you have snippets that restart each of these services. Instead of maintaining nearly identical snippets, you can set an environment variable for each Host and reference it in a Snippet:
On each Host, set the same variable name with its own value, see Environment variables:
Create a
Snippetthat references the variable instead of a hardcoded service name:
Run the snippet on any of these Hosts. It restarts whichever service is actually correct on that machine:
nginxonweb-01,gunicornonapi-02
Last updated
Was this helpful?

