Are you sure you want to delete this access key?
title | intro | redirect_from | versions | topics |
---|---|---|---|---|
Managing deploy keys | Learn different ways to manage SSH keys on your servers when you automate deployment scripts and which way is best for you. | [/guides/managing-deploy-keys/ /v3/guides/managing-deploy-keys] | [{free-pro-team *} {enterprise-server *} {github-ae *}] | [API] |
You can manage SSH keys on your servers when automating deployment scripts using SSH agent forwarding, HTTPS with OAuth tokens, deploy keys, or machine users.
In many cases, especially in the beginning of a project, SSH agent forwarding is the quickest and simplest method to use. Agent forwarding uses the same SSH keys that your local development computer uses.
ssh -A serverA 'bash -s' < deploy.sh
If you don't want to use SSH keys, you can use HTTPS with OAuth tokens.
See our guide on Git automation with tokens.
{% data reusables.repositories.deploy-keys %}
{% data reusables.repositories.deploy-keys-write-access %}
ssh-keygen
procedure on your server, and remember where you save the generated public/private rsa key pair.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:
Host {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-0
Hostname {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}
IdentityFile=/home/user/.ssh/repo-0_deploy_key
Host {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-1
Hostname {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}
IdentityFile=/home/user/.ssh/repo-1_deploy_key
Host {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-0
- The repository's alias.Hostname {% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}
- Configures the hostname to use with the alias.IdentityFile=/home/user/.ssh/repo-0_deploy_key
- Assigns a private key to the alias.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:
$ git clone git@{% if currentVersion == "free-pro-team@latest" %}github.com{% else %}my-GHE-hostname.com{% endif %}-repo-1:OWNER/repo-1.git
If your server needs to access repositories across one or more organizations, you can use a GitHub App to define the access you need, and then generate tightly-scoped, server-to-server tokens from that GitHub App. The server-to-server tokens can be scoped to single or multiple repositories, and can have fine-grained permissions. For example, you can generate a token with read-only access to a repository's contents.
Since GitHub Apps are a first class actor on {% data variables.product.product_name %}, the server-to-server tokens are decoupled from any GitHub user, which makes them comparable to "service tokens". Additionally, server-to-server tokens have dedicated rate limits that scale with the size of the organizations that they act upon. For more information, see Rate limits for Github Apps.
id
.installation_id
that represents the connection between your GitHub App and the organization repositories it can access. Each GitHub App and organization pair have at most a single installation_id
. You can identify this installation_id
via Get an organization installation for the authenticated app. This requires authenticating as a GitHub App using a JWT, for more information see Authenticating as a GitHub App.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 on a personal repository (granting read and write access), as an outside collaborator on an organization repository (granting read, write, or admin access), or to a team with access to the repositories it needs to automate (granting the permissions of the team).
{% if currentVersion == "free-pro-team@latest" %}
{% tip %}
Tip: Our terms of service state:
Accounts registered by "bots" or other automated methods are not permitted.
This means that you cannot automate the creation of accounts. But if you want to create a single machine user for automating tasks such as deploy scripts in your project or organization, that is totally cool.
{% endtip %}
{% endif %}
ssh-keygen
procedure on your server and attach the public key to the machine user account.Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?