Skip to content

Commit 2db2a7e

Browse files
authored
Merge pull request #501 from tarrenj/multiple-deploy-keys
Multiple deploy keys
2 parents d8db215 + eca5ebb commit 2db2a7e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

content/developers/overview/managing-deploy-keys.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,32 @@ See [our guide on Git automation with tokens][git-automation].
8383
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.
8484
8. Click **Add key**.
8585

86+
##### Using multiple repositories on one server
87+
88+
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.
89+
90+
In the server's SSH configuration file (usually `~/.ssh/config`), add an alias entry for each repository. For example:
91+
92+
```bash
93+
Host {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-0
94+
Hostname {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}
95+
IdentityFile=/home/user/.ssh/repo-0_deploy_key
96+
97+
Host {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-1
98+
Hostname {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}
99+
IdentityFile=/home/user/.ssh/repo-1_deploy_key
100+
```
101+
102+
* `Host {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-0` - The repository's alias.
103+
* `Hostname {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}` - Configures the hostname to use with the alias.
104+
* `IdentityFile=/home/user/.ssh/repo-0_deploy_key` - Assigns a private key to the alias.
105+
106+
You can then use the hostname's alias to interact with the repository using SSH, which will use the unique deploy key assigned to that alias. For example:
107+
108+
```bash
109+
$ git clone git@{% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-1:OWNER/repo-1.git
110+
```
111+
86112
### Machine users
87113
88114
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).

0 commit comments

Comments
 (0)