Score:0

How to use multiple ssh keys for one connection?

cn flag

My organization has a server that requires two identity files simultaneously for one ssh connection. Just like this: ssh -i /first/key -i /second/key user@host And i am wondering how does it implemented? How to configure my own SSH server to make it require two identity files at the same time for one client?

Score:1
in flag

This is controlled by the AuthenticationMethods section of the OpenSSH configuration. From the documentation, the most relevant section is this:

If the publickey method is listed more than once, sshd(8) verifies that keys that
have been used successfully are not reused for subsequent authentications.  For
example, "publickey,publickey" requires successful authentication using two
different public keys.

This is exactly what you are asking to do. So, with this in mind, let's get it done.

On the server ...

  1. Create a new file for the AuthenticationMethods option:
    sudo {editor of choice} /etc/ssh/sshd_config.d/two_key.conf
    
    Note: Be sure to replace {editor of choice} with your editor of choice.
  2. Add this line to the file:
    AuthenticationMethods publickey,publickey 
    
  3. Save the file and restart OpenSSH Server:
    sudo service sshd restart 
    
  4. Ensure both (or all) of your public keys are properly added to ~/.ssh/authorized_keys
  5. Connect from another machine:
    ssh -i /first/key -i /second/key user@host 
    

That's all there is to it

Georgiy List'ev avatar
cn flag
Thanks! That is exactly I was looking for.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.