7

I can see that GitHub allows you to have multiple mail account and associate every organization you are part of with a different address.

Can this be done also for SSH keys?

What I would like to do is having two different keys, one to push on my private repository, another to push on an organization repository.

0

2 Answers 2

3

On Github, you can add several ssh keys to your account, simply go to your profile/ssh and click "Add SSH key".

But as far as I know the permissions for a repository is associated to the account, not the key. So if you are trying to limit the damage done by someone stealing your key, I believe you will need to create two accounts.

2
  • After thinking on this issue, I came to the same conclusion. Hence accept. Besides, the authentication is per user, so once a user is authenticated, there's no way of denying access to a certain directory basing on the used ssh key. At least, intuitively.
    – Dacav
    Commented May 2, 2013 at 10:13
  • 2
    This appears to be the correct answer, but it is so disappointing. I want to have access to my repos from multiple computers... some I want access to private personal repos, and others I need access to repos for work through my Organization membership. I have different security needs for these things. Due to the way this works, I'm forced to implement the tightest security measures on all computers or set up separate accounts. I feel GitHub could solve this.
    – Ryan
    Commented Mar 21, 2018 at 15:24
2

Things have changed quite a bit since this answer. There is now a path to do exactly what OP is requesting via fine grained Personal Access Tokens. The fine grained permission ability is (currently) in beta, but allows you to generate a token with least privilege, and tie it to a specific repository.

You can then use GitHub HTTP authentication (instead of SSH) to be able to push commits.

  1. Generate a personal access token in GitHub user settings (Settings → Developer settings → Personal access tokens → Fine Grained Tokens (beta) → Generate new token*)
  • Be sure to grant Read / Write to Code and Commit Statuses
  1. Add this token to your .git/config like so:
[remote "origin"]
    url = https://username:[email protected]/username/repo.git

Not the answer you're looking for? Browse other questions tagged or ask your own question.