SSH Client and SSH Server Environment Variables

SSH client environment variables can be passed to the server, but the server must explicitly allow them in sshd_config for them to be accepted.

1. Setting Environment Variables on the SSH Client

On the client machine, you can configure SSH to send specific environment variables by adding them to ~/.ssh/config:

                                    
Host remote-server SendEnv hiddenssh oracle-api-key

Alternatively, you can set and send an environment variable inline when connecting:

hiddenssh="supersecret" oracle-api-key="myapikey123" ssh user@remote-server         

2. Allowing Environment Variables on the SSH Server

On the server (/etc/ssh/sshd_config), you must explicitly allow these variables:

AcceptEnv hiddenssh oracle-api-key        

After making changes, restart the SSH service to apply them:

sudo systemctl restart sshd           

3. Setting Static Environment Variables on the Server

If you want to set environment variables globally on the server without requiring them from the client, you can define them in:

📌 /etc/environment (System-Wide Variables)

                                     
hiddenssh="server-secret"
oracle-api-key="server-api-key"

📌 Or in ~/.bashrc (Per-User Session Variables)

                                             
export hiddenssh="server-secret"
export oracle-api-key="server-api-key"

4. Checking SSH Environment Variables

To verify if the variables were passed after SSH login, run:

env | grep -E "hiddenssh|oracle-api-key"          
printenv | grep -E "hiddenssh|oracle-api-key"       
env    

Summary

🚀 Now your SSH session can securely pass hiddenssh and oracle-api-key variables! 🔐