7

I'm following these instructions for how to set up SSH keys for use with GitHub.

The instructions tell you to delete your current .ssh directory and create new keys in that .ssh directory. I'm unable to do this as I already have keys in my id_dsa.pub that I need to use for other servers.

Is it possible to set up SSH for GitHub while preserving the keys I already have saved in .ssh? Or is there another way to set up SSH for GitHub?

3 Answers 3

10

You can either reuse your key pair already in your directory, or create a new key-pair specifically for GitHub's use. If you decide not to use the default pair, you'll need to modify your ~/.ssh/config file and add a host definition for GitHub pointing it to the new key file. So, if your new key pair is github_rsa and github_rsa.pub, put these lines in /.ssh/config:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_rsa

Now, whenever you do pull or push operations to [email protected], the alternate identity file will be used.

Sign up to request clarification or add additional context in comments.

Comments

7

You can generate keys with specific names like:

ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "[email protected]"

And then you can specify this key for a separate server in the ~/.ssh/config file:

Host *github.com
  IdentityFile ~/.ssh/id_rsa_github
  User git

See man ssh or man ssh_config for more details.

2 Comments

User needs to be set to git - I've made that change.
I dont find the config file
0

Make sure you have this in the global configuration:

git config --global credential.helper osxkeychain

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.