AuthenticationGitHub
Deploy keys, SSH keys and machine users on GitHub
GitHub documents several ways for a server to reach a repository. They differ in how many repositories each credential covers, whether it expires, and whether it belongs to a person.

Deploy keys
A deploy key is an SSH key whose access covers exactly one repository. GitHub attaches the public part to the repository, and the private part stays on the server. The key is read-only by default. You can give it write access when you add it, and you cannot reuse it for another repository.
The GitHub CLI manual gives these two commands, which create a key with no passphrase and add it as a deploy key:
ssh-keygen -t ed25519 -C "my description" -N "" -f ~/.ssh/gh-test
gh repo deploy-key add ~/.ssh/gh-test.pubgh repo deploy-key add takes --repo to select another repository, --title to name the key and --allow-write to allow write access. In the web interface, the same form is in the repository under Settings, Deploy keys, Add deploy key.
GitHub's documentation lists these properties:
- A deploy key has no expiry date.
- It is tied to the repository. It stays active when the user who created it is removed from the repository.
- Given write access, it can do what an organization member with admin access can do.
- A key added by the CLI is associated with the CLI's authentication token. If you de-authorize that token, the deploy key is removed as well.
Several repositories on one server
Each repository needs a dedicated key pair. GitHub's documentation adds an alias for each repository to the server's SSH configuration file, which it gives as ~/.ssh/config:
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_keyYou then clone through the alias, with your own owner in place of OWNER:
git clone [email protected]:OWNER/repo-1.gitPersonal SSH keys
A user SSH key is added to a personal account. GitHub's credential reference lists it as associated with the user account, where a deploy key is associated with a repository. GitHub deletes a user SSH key that has not been used for a year.
The deploy key documentation describes one way to deploy with personal keys, SSH agent forwarding. A user's permissions on the server equal the ones they have locally, and the server stores no keys. Users must connect over SSH to deploy, so automated deploy processes cannot use it.
Machine users
A machine user is a GitHub account that is used only for automation and has its own SSH key. It joins a repository as a collaborator, as an outside collaborator or through a team. One key for each server is then enough for all the repositories the account can access.
GitHub's terms of service do not permit accounts registered by automated methods. Its documentation says a single machine user for tasks such as deploy scripts is acceptable.
The documented drawback: only organizations can restrict a machine user to read-only access. A personal repository always grants collaborators read and write access.
GitHub Apps as the alternative
A GitHub App generates installation access tokens that work with the REST and GraphQL APIs and with a Git client. A token can be scoped to one repository or several and can have fine-grained permissions, such as read-only access to a repository's contents. It expires after one hour. It is decoupled from any GitHub user, so it consumes no licensed seat.
GitHub's deploy key documentation recommends a GitHub App for enhanced security and fine-grained control over repository access. The drawbacks it lists are the additional setup and the need to regenerate the token when it expires.
The organization setting
Organization owners choose whether members can create deploy keys, under Settings, Member privileges, Deploy keys. New organizations are configured to disallow it.
Read the warning before you change the setting on an existing organization. Changing it to Disabled disables the existing deploy keys in all repositories of the organization. An enterprise owner can set a policy at the enterprise level, and then the organization may be unable to change the setting.
How to choose
- One server pulls one repository: a deploy key, left read-only.
- One server pulls several repositories: a deploy key for each with SSH aliases, or a GitHub App, whose tokens can cover several repositories.
- You need a credential that expires, or fine-grained permissions: a GitHub App.
- You want one key for each server across many repositories: a machine user, in an organization so that its access can be read-only.
To review what exists, run gh repo deploy-key list in each repository, or add --repo to name it. Remove the keys nobody can account for, and replace any key that has write access and does not need it.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

GitHub Apps or personal access tokens for automation
Authentication · 4 min read
Ownership, lifetime, permissions and rate limits compared, with a workflow that creates an app token.

Fine-grained personal access tokens on GitHub
Authentication · 4 min read
What a fine-grained token limits, what it cannot do today, and when a GitHub App fits better.

Signed commits: GPG, SSH and what the Verified badge proves
Supply chain · 4 min read
SSH signing in four commands, what Verified means, and why rebase merges lose verification.