Environment variables
This page explains how to configure, pass, and verify environment variables in remote SSH sessions, including server-side AcceptEnv rules.
Last updated
Was this helpful?
This page explains how to configure, pass, and verify environment variables in remote SSH sessions, including server-side AcceptEnv rules.
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.
LANG=en_US.UTF-8
APP_ENV=stagingEnvironment variables can be set on both Hosts and Groups. When set on a Group, every Host inside the Group inherits that setting, see How hosts inherit group properties.
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.
Some environment variables could be used to bypass restricted user environments, so AcceptEnv directives should be added deliberately rather than broadly. This is also why the default is to accept none at all.
# 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.
Open the Host details, scroll to the credential section and click Show more

Click Environment Variable

Click Add a variable, add your variable as VARIABLE(KEY)=VALUE, then Save

To confirm the variable is set correctly, you can echo it once connected. If it prints the expected value, the variable is set. If it's empty, double-check that the variable name matches the AcceptEnv pattern in sshd_config , see Accepted environment variables above

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 Snippet that 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: nginx on web-01, gunicorn on api-02
Last updated
Was this helpful?
Was this helpful?
# Hosts: web-01, web-02, web-05
SERVICE_NAME=nginx
# Hosts: api-02, api-03
SERVICE_NAME=gunicornsudo systemctl restart $SERVICE_NAME
