Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Have you considered setting your variables in ~/.ssh/rc? Or how about environment="NAME=value". – Zoredache Mar 27 '12 at 22:00
Thanks, Zoredache. environment param solves my problem. You can add your solution as an answer to this question, I would accept it for you to get reputation points. – Laurynas Mar 28 '12 at 10:45

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:

ssh myhost uptime

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 your authorized_keys file.

share|improve this answer
Thanks for the answer, but my problem was that I want to set environment variables per ssh key. It was solved by Zoredache suggestion. – Laurynas Mar 28 '12 at 10:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.