I would like to use command per key in authorized_keys to set some environment variables.
command="MYVAR=test $SHELL" ssh-rsa mykey
Shell works fine but scp is not working.
What would be the correct way to set environment variables per key and not break ssh file transfers?
Best Answer
Your configuration forces ssh to run whatever command is in
$SHELL
whenever you connect with the matching private key. This is fine if what you want is an interactive shell, but will break any attempt at running a command directly. This breaks `scp as you've seen, but will also break things like:The solution is to either (a) set your environment variables somewhere else (
.ssh/rc
, or just use your standard shell initialization files), or (b) use a dedicated key when you want to force a command via yourauthorized_keys
file.