Edit: The hint for restarting ssh after editing /etc/ssh/sshd_config solved my issue (sudo systemctl restart ssh.service
on Ubuntu) but see the accepted answer for a lot more of useful troubleshooting.
Original:
I have a server which I connect to via a jump host:
export MY_ENV=myvalue
ssh -o StrictHostKeyChecking=yes -o SendEnv=MY_ENV -J <myuser@jumpHostIp> <myuser@hostIp>
Both the jump host and the host have in their /etc/ssh/sshd_config:
AcceptEnv MY_ENV
Both the jump host and the host have in their /home/myuser/.ssh/authorized_keys the ssh key limiting myuser to a deploy script:
command=/home/myuser/deploy.sh ...rest of public key...
Inside this deploy.sh I would like to use $MY_ENV, however it does not work.
Is using a jump host somehow dropping the value of MY_ENV transfered by SendEnv? If yes is this intended or how can I access the value of MY_ENV in deploy.sh on the host?
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:
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
After a change of the
sshd_config
the sshd has to be restarted to read the updated configuration.(the solution for this question ...)
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 commandThe whole PublicKey-Authentication will fail, when omitting the
"
quotations enclosing the value of thecommand
option:Depending on the settings in
sshd_config
a fallback to password based authentication, respectively aPermission denied (publickey).
will follow.The
"
quotations are required, even if there is no white space in the command: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:
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:
... despite the fact that the variable shows up in the current shell.
Required: