For the complete documentation index, see llms.txt. This page is also available as Markdown.

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=staging

Environment 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.

Accepted 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_ENV

With 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

  1. Open the Host details, scroll to the credential section and click Show more

  2. Click Environment Variable

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

  4. 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

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:

  1. On each Host, set the same variable name with its own value, see Environment variables:

  1. Create a Snippet that references the variable instead of a hardcoded service name:

  1. 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?