This question is similar to SSH public key authentication - can one public key be used for multiple users? but it's the other way around.
I'm experimenting on using ssh so any ssh server would work for your answers.
Can I have multiple public keys link to the same user? What are the benefits of doing so? Also, can different home directories be set for different keys used (all of which link to the same user)?
Please let me know if I'm unclear.
Thanks.
You can have as many keys as you desire. It's good practice to use separate private/public key sets for different realms anyway, like one set for your personal use, one for your work, etc.
First, generate two separate keypairs, one for home and one for work:
Next, add an entry to your
~/.ssh/config
file to pick the key to use based on the server you connect to:Next, append the contents of your
id_rsa.work.pub
into~/.ssh/authorized_keys
on the work machine, and do the same for the home key on your home machine.Then when you connect to the home server you use one of the keys, and the work server you use another.
Note you probably want to add both keys to your
ssh-agent
so you don't have to type your passphrase all the time.It makes lots of sense to have multiple users' keys going to one user. Common reasons are:
Push URL: git+ssh://git@git-server/~/repos/MyProject
)As far as having different homedirs, you can change them per key by prepending
environment="HOME=/home/user1"
for user1's key in the authorized_keys file. Seeman authorized_keys
.Try it out, YMMV.