Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.