Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Suppose I have a number of accounts on a server called SERVER. Let's call them ACCOUNT1, ACCOUNT2 and ACCOUNT3.

Suppose I don't want to have to type in the password for the account each time I ssh into one of those accounts from my local computer, DESKTOP.

Obviously, I could use a single ssh key pair to allow myself passwordless login to all three accounts, but is it possible to use a different ssh key pair for each account?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

You can manage these identities with ~/.ssh/config. For example:

Host acc1-server
     User ACCOUNT1
     Hostname SERVER
     IdentityFile ~/.ssh/id-ACC1-SRV

Host acc2-server
     User ACCOUNT2
     Hostname SERVER
     IdentityFile ~/.ssh/id-ACC2-SRV

Afterwards just type ssh acc1-server to connect to SERVER as ACCOUNT1 with key ~/.ssh/id_rsa-ACC1-SRV, or ssh acc2-server to connect to SERVER as ACCOUNT2 with key ~/.ssh/id_rsa-ACC2-SRV ;-)

share|improve this answer

Yes, you can have a different keypair for each account; just mind the options when you run ssh-keygen and specify different identity files for them.

If your local computer is acceptably secure and you don't want to continuously re-enter your key password, ssh-agent might be worth looking into as well.

share|improve this answer
I'm using ssh-agent. It's happy enough with multiple keys, one per server, but doesn't seem to accept I might want to use a different key with each account on a single given server. If you think I'm doing something wrong with ssh-agent, please say :) –  sampablokuper Apr 23 '11 at 19:18
Ah, it might be a Mac OS X specific problem with ssh-agent: shawndavison.com/2010/06/… (In my case, DESKTOP happens to be running Snow Leopard.) –  sampablokuper Apr 23 '11 at 19:29
@sampablokuper: You never mentioned what you are doing with your ssh-agent, nor what kinds of entries you are using in your .ssh/config. –  Chris Johnsen Apr 24 '11 at 2:21
@Chris, sorry. I didn't have an .ssh/config, & I asked the question partly to troubleshoot what seemed to be odd behaviour by ssh-agent on DESKTOP. (I wanted to pose the question as a general one, though, so that others might benefit.) Turns out the behaviour was caused by either the .ssh directory not being executable or the .ssh/authorized_keys being misconfigured, on all but one of the remote accounts! Until I fixed this, it had appeared to me that ssh-agent just wouldn't use more than one SSH key per server, since on all but one account SSH would ask for the password regardless. –  sampablokuper Apr 24 '11 at 16:21
If you have more than one identity loaded into the agent, it will offer to authenticate with any of them in order against the other end. So if you have identities A, B and C loaded, and account 1 only has B's public key in ~/.ssh/authorized_keys then your client will attempt to auth with key A, be told that account 1 doesn't seem to accept key A, then attempt key B and get authenticated. –  Shadur Apr 24 '11 at 19:17

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.