Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple deploy keys #501

Merged
merged 20 commits into from
Nov 13, 2020
Merged
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions content/developers/overview/managing-deploy-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ See [our guide on Git automation with tokens][git-automation].
7. Select **Allow write access** if you want this key to have write access to the repository. A deploy key with write access lets a deployment push to the repository.
8. Click **Add key**.

##### Using multiple repositories on one server

If you use multiple repositories on one server, you will need to generate a dedicated key pair for each one. You can't reuse a deploy key for multiple repositories.

In the server's SSH configuration file (usually `~/.ssh/config`), add an alias entry for each repository. For example:

```bash
Host github.com-repo-0
Hostname github.com
IdentityFile=/home/user/.ssh/repo-0_deploy_key

Host github.com-repo-1
Hostname github.com
IdentityFile=/home/user/.ssh/repo-1_deploy_key
```

* `Host github.com-repo-0` - The repository's alias.
* `Hostname github.com` - Configures the alias to use the {% data variables.product.product_name %} server.
martin389 marked this conversation as resolved.
Show resolved Hide resolved
* `IdentityFile=/home/user/.ssh/repo-0_deploy_key` - Assigns a private key to the alias.

With these entries added, you can then use the alias to clone a repository, and the unique deploy key is automatically presented. For example:
martin389 marked this conversation as resolved.
Show resolved Hide resolved

```bash
$ git clone git@github.com-repo-1:github-user/repo-1.git
martin389 marked this conversation as resolved.
Show resolved Hide resolved
```
martin389 marked this conversation as resolved.
Show resolved Hide resolved

### Machine users

If your server needs to access multiple repositories, you can create a new {% data variables.product.product_name %} account and attach an SSH key that will be used exclusively for automation. Since this {% data variables.product.product_name %} account won't be used by a human, it's called a _machine user_. You can add the machine user as a [collaborator][collaborator] on a personal repository (granting read and write access), as an [outside collaborator][outside-collaborator] on an organization repository (granting read, write, or admin access), or to a [team][team] with access to the repositories it needs to automate (granting the permissions of the team).
Expand Down