DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Cover image for Using another private key with git
Adam K Dean
Adam K Dean

Posted on

Using another private key with git

It's quite normal to have different private keys for different git servers, but how do you provide a different identity file like you do with SSH?

The answer comes in a text file; config.

Create a text file in your ssh directory, which is usually .ssh:

$ touch ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Then open it with your favourite text editor, for me, this is currently atom:

$ atom ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Now, we can use this file to configure different hosts. The following should be pretty self explanatory. For your information, in case you're a bit confused, the identity file is your private key.

Host example.com
    HostName git.example.com
    User git
    IdentityFile /Users/adam/.ssh/yourkey
    IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

You'll notice the host and hostname are different. This means you can have a host configured for example.com which actually points to another hostname, such as a source control server, e.g. git.example.com.

Top comments (0)

๐ŸŒš Browsing with dark mode makes you a better developer.

It's a scientific fact.