I have two SSH keys 'personal' and 'work'.

With them I need to connect to a service: user@service.com.

The keys are linked to two accounts on service.com, however in SSH they both have to use the same user 'user'. Thus I can't use ~/.ssh/config and 'Host's to route the two keys to the correct accounts. As a result, I put the 'work' key into ~/.ssh/config using Host, and comment it out when wanting to do stuff with my 'personal' key.

My question is, is there a better way to handle this?

When I interact with that service, I will source somefile.sh anyway so having some environment variable in there to handle the routing would be ideal, but I can't find a way to change, for example, the ssh config file path, using environment variables.

I don't use ssh directly but rather through a 3rd party tool.

Is there such a variable?

I'm on Linux (Ubuntu).


You could have two entries in ~/.ssh/config and have whatever settings you need:

Host work
User workid
HostName service.com

Host personal
User homeid
HostName service.com

Then you can do ssh work and ssh personal.

Basically the trick is: the Host part does not have to be a real DNS host name, it can be whatever you want.

|improve this answer|||||
  • 1
    I should have added: I can't actually use ssh directly. It's done through a 3rd party command line tool. – ojii Nov 10 '11 at 19:28
  • 2
    Does that mean you have no control over the command? Because you could also use ssh -F myfile to override $HOME/.ssh/config – Kevin Panko Nov 10 '11 at 19:32
  • 1
    This is the tool I'm using: github.com/epio/epio-client, specifically this bit of code: github.com/epio/epio-client/blob/master/epio/commands/run.py So I cannot directly modify the ssh party, but the environment of it. – ojii Nov 10 '11 at 19:33
  • 1
    You could modify $HOME but that's going to cause its own problems. I recommend changing that python code to use ssh -F if you set something in the environment. – Kevin Panko Nov 10 '11 at 19:39
  • 1
    just to clarify, -F /path/to/other/ssh-config? As in -F points to the config file? EDIT: Nevermind, did the man ssh thing and found out. Thanks – ojii Nov 10 '11 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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