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.
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
SendEnv → Defines which environment variables the client sends to the SSH server.hiddenssh and oracle-api-key during the SSH connection.Alternatively, you can set and send an environment variable inline when connecting:
hiddenssh="supersecret" oracle-api-key="myapikey123" ssh user@remote-server
On the server (/etc/ssh/sshd_config), you must explicitly allow these variables:
AcceptEnv hiddenssh oracle-api-key
AcceptEnv → Defines which environment variables SSHD will accept from the client.After making changes, restart the SSH service to apply them:
sudo systemctl restart sshd
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"
~/.bashrc (Per-User Session Variables)
export hiddenssh="server-secret"
export oracle-api-key="server-api-key"
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
SendEnv) → Specifies which variables to send.AcceptEnv) → Must explicitly allow these variables in sshd_config.env or printenv → To confirm variables are set.🚀 Now your SSH session can securely pass hiddenssh and oracle-api-key variables! 🔐