Edit: I refined the details regarded during our iteration process, partly dubbing some details already named in the question for better general use.
The man page of ssh states:
Note that configuration directives supplied on the command-line generally apply to the destination host and not any specified jump hosts. Use ~/.ssh/config to specify configuration for jump hosts.
So your final destination will receive the options added by -o
. As the options are not touched by the jump host, it is not necessary to configure the jump host for the variables to pass to the destination host.
Config of sshd at the destination server
As a prerequisite the destination-host's sshd service has to be configured to accept the environment variable. Wildcards are allowed:
File: /etc/ssh/sshd_config
AcceptEnv MY_*
After a change of the sshd_config
the sshd has to be restarted to read the updated configuration.
(the solution for this question ...)
systemctl restart sshd
The current connection will persist, when restarting the sshd (at least when using "openssh-server"
Pitfall in authorized_keys
To limit the key-usage at the destination system, an option can be added to the authorization.
File: authorized_keys
with limitation to a command
The whole PublicKey-Authentication will fail, when omitting the "
quotations enclosing the value of the command
option:
command=/home/user/deploy.sh ssh-rsa AAAAB3NzaC1yc2EAA...
# DEBUG response of sshd:
debug1: /home/user/.ssh/authorized_keys:1: bad key options: missing start quote
Depending on the settings in sshd_config
a fallback to password based authentication, respectively a Permission denied (publickey).
will follow.
The "
quotations are required, even if there is no white space in the command:
command="/home/user/deploy.sh" ssh-rsa AAAAB3NzaC1yc2EAA...
Details for the client's command
Note: Besides the command-line options these details can be configured at the client user's ~/.ssh/config
.
To pass the desired variable as option at the command-line two variants are possible as syntax:
-o SendEnv=MY_ENV
-o "SendEnv MY_ENV"
Please do not forget the "
quotes.
Essential for the availbility of the variable is not only to set it, you have to export it:
This will fail:
MY_ENV="Value"
echo $MY_ENV
Value
... despite the fact that the variable shows up in the current shell.
Required:
export MY_ENV="Value"