9

I want to access a host with a specific user, but I want this user to have multiple SSH keys.

Why? This is the user for deployment on the server and there are multiple developers who have to deploy. I'd like to use a different key for each developer. (Yes, I could create multiple deployment users, but that's quite costly on this managed server)

Example:

bob@bobs-workstation$ ssh -i ~/.ssh/id_rsa.bob       deploy@host.com
alice@alices-workstation$ ssh -i ~/.ssh/id_rsa.alice deploy@host.com

Is this even possible?

In similar questions it's always about different users or different hosts and multiple SSH keys, but in this case it's about the same user and the same host with multiple SSH keys.

TeeTrinker
  • 311
  • 2
  • 14
  • Does this answer your question? [How to use multiple SSH keys for the same host?](https://stackoverflow.com/questions/14888056/how-to-use-multiple-ssh-keys-for-the-same-host) – Arty-chan Jan 19 '20 at 20:09
  • @Arty-chan it's fairly similar, but it doesn't answer the specific question here, because it is once more about multiple users. Maybe it would be a good idea to give a more exhaustive answer in the other question and include the info about the same user on the same server with different keys? Then this question would be obsolete. – TeeTrinker Jan 22 '20 at 02:15

1 Answers1

12

Turns out I found no questions about that because it's the most trivial case there is:

Yes, it's possible for a single user to accept multiple public SSH keys. The text of the key files all have to be copied into /home/deploy/.ssh/authorized_keys (deploy was the user in the above example).

This is what the content of authorized_keys could look like:

    ssh-rsa *bobsunintellegiblepublickeyformultiplelines* bob_at_deploy@host.com
    ssh-rsa *alicesunintellegiblepublickeyformultiplelines* alice_at_deploy@host.com
TeeTrinker
  • 311
  • 2
  • 14
  • Where does the above authorized_keys file help ? In mys case, the single user accepts multiple public ssh keys, even by just adding the keys to the ssh agent and then configuring the ssh config file – AlwaysLearning Aug 12 '22 at 09:09
  • Perosnally I was wondering if there is a way to avoid writing the whole repo url after every command if you want to specify the user e.g. git pull username@bitbucket.org/company-name/repo.git – AlwaysLearning Aug 12 '22 at 09:11
  • 1
    @AlwaysLearning I think you might have a different case than I did. In my case username@bitbucket.org/company-name/repo.git is always the same, both "bob" and "alice" would use username@ They would NOT use alice@ or bob@ Your case is probably the normal one, i.e. multiple real people have multiple ssh users with access to one host. Maybe this link helps for your case: https://stackoverflow.com/questions/14888056/how-can-i-use-multiple-ssh-keys-for-the-same-host – TeeTrinker Aug 14 '22 at 16:45
  • 1
    yes you are right, this is exaclty my case: "Your case is probably the normal one, i.e. multiple real people have multiple ssh users with access to one host" – AlwaysLearning Aug 22 '22 at 11:00