> For the complete documentation index, see [llms.txt](https://docs.termius.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.termius.com/terminal/environment-variables.md).

# Environment variables

## 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

```bash
LANG=en_US.UTF-8
APP_ENV=staging
```

{% hint style="info" %}
Environment variables can be set on both Hosts and Groups. When set on a Group, every Host inside the Group inherits that setting, see [Groups and tags](/organize-and-connect-to-hosts/groups-and-tags.md#how-hosts-inherit-group-properties).
{% endhint %}

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

{% hint style="warning" %}
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.
{% endhint %}

#### Example

```bash
# 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`

   <figure><img src="/files/9MuQqeDdLm1DhvodMGKw" alt=""><figcaption></figcaption></figure>
2. Click `Environment Variable`

   <figure><img src="/files/AplXU97yfodkCDhYRbIS" alt=""><figcaption></figcaption></figure>
3. Click `Add a variable`, add your variable as `VARIABLE(KEY)=VALUE`, then `Save`

   <figure><img src="/files/XEO7Gw5TzdB02ecZauM6" alt=""><figcaption></figcaption></figure>
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](#accepted-environment-variables) above

   <figure><img src="/files/LRdSCfpTJsGrMTylSnQV" alt=""><figcaption></figcaption></figure>

## 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](/terminal/snippets.md):

1. On each Host, set the same variable name with its own value, see [#set-an-environment-variables](#set-an-environment-variables "mention"):

```bash
# Hosts: web-01, web-02, web-05
   SERVICE_NAME=nginx

# Hosts: api-02, api-03
   SERVICE_NAME=gunicorn
```

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

```bash
sudo systemctl restart $SERVICE_NAME
```

3. 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`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.termius.com/terminal/environment-variables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
