DEV Community

Cover image for Multiple ssh keys
Gustav Ehrenborg
Gustav Ehrenborg

Posted on

Multiple ssh keys

Yesterday, I was gonna add my ssh key to Azure DevOps, to be able to contribute to a repository. I was presented with the following:

Error from DevOps

Apparently, DevOps does only support rsa keys, and not ed25519 keys, even though ed25519 is considered to be more secure. The ed25519 is also the default algorithm in GitHub's guide to setting up keys which many people follow.

Generating a new rsa key is the solution to this. However, having multiple ssh keys on the same machine presented new problems. I want to use my ed25519 key as much as possible, for example on repositories on GitHub, but how do I tell my computer to use the rsa key for the repository on Azure DevOps?

Apparently, there is a file, ~/.ssh/config, that solves these kind of troubles. You probably have a couple of lines in it, like this:

Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

These lines tells the ssh client to automatically add keys to the running agent and use the key in ~/.ssh/id_ed25519, for all hosts.

By adding these lines:

Host ssh.dev.azure.com
  IdentityFile ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

We tell the ssh client to use the key ~/.ssh/id_rsa when connecting to ssh.dev.azure.com, which is the host of the repositories.

Simple as that!

Bonus 1

If you tired of writing the entire ssh username@some-host.com:xxxx when using ssh, aliases can be configured:

Host my-alias
    HostName some-host.com
    User username
    Port xxxx
Enter fullscreen mode Exit fullscreen mode

Now ssh my-alias will be enough to connect.

Bonus 2

If you ever find yourself on a network were port 22 is blocked and you want to use ssh to connect GitHub, you can use ssh over port 443 instead. Just add this configuration.

Host github.com
  Hostname ssh.github.com
  Port 443
Enter fullscreen mode Exit fullscreen mode

Top comments (0)