# git@github.com: Permission denied (publickey) — how to fix it

> GitHub's SSH server did not accept any key from your machine, so git cannot read the repository. Either there is no key, the key is not on your GitHub account, the SSH agent does not offer it, or the connection is not made as the git user. Test with ssh -T git@github.com, then add a key, switch the remote to HTTPS with a token, or give a server a deploy key.

Source: https://livops.dev/en/guides/error-git-permission-denied-publickey

By Livops team, the people who build and run Livops. Updated 3 December 2026.

`git clone`, `git pull` or `git push` stops with this:

```text
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
```

The first line comes from SSH, which prints the user and host it tried and the authentication methods the server would have accepted[9]. The rest comes from git, which only knows that the connection gave it nothing to read[10]. This page explains what was refused, how to see why in one command, the fixes from the most common cause, the HTTPS alternative, and what to do on a server.

## What does the error mean?

GitHub's SSH server rejected the connection[1]. `(publickey)` is the only method it allows, and your SSH client either offered no key or offered keys that are not attached to any GitHub account. Nothing is wrong with the repository or with git; the problem is the key, the agent that should offer it, or the address you connect to.

## Test the connection first

Run this from the same machine and the same user that runs git:

```sh
ssh -T git@github.com
```

When SSH works, GitHub greets you by name and closes the session, because it gives no shell; the command exits with code 1 even on success[2]:

```text
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
```

The first time, SSH asks whether to trust `github.com`; compare the fingerprint with the one GitHub publishes before you type `yes`[2]. If you get `Permission denied (publickey)` instead, ask for the details:

```sh
ssh -vT git@github.com
```

Read three things in the output[1]:

- **`Connecting to github.com port 22`.** You reach the right host on the usual port.
- **`identity file ... type -1`.** SSH found no key file at that path. A key that exists shows a type other than `-1`.
- **`Offering public key: ...`.** SSH sent that key. If keys are offered and still refused, usually none of them is on your GitHub account. If no key is offered at all, the machine has none that SSH knows about.

## Causes, most common first

### 1. There is no SSH key on this machine

A new laptop, a fresh server or a container has no key. `ssh-add -l -E sha256` prints nothing, and `ssh -vT` shows only `type -1` lines[1]. Generate one and add it to GitHub, below.

### 2. The key is not on your GitHub account

The key exists and is offered, but GitHub does not know it. Compare the fingerprint the agent shows with the list in GitHub's **Settings → SSH and GPG keys**[1]:

```sh
ssh-add -l -E sha256
```

If it is not in the list, add the public key, below.

### 3. The agent does not offer the key

A key saved under a name other than the default, such as `~/.ssh/work_ed25519`, is not tried until you add it to the agent or name it in `~/.ssh/config`[1]. Test a specific file directly:

```sh
ssh -i ~/.ssh/work_ed25519 -vT git@github.com
```

If that works, load the key with `ssh-add` or add an `IdentityFile` line for `github.com`, below.

### 4. The wrong user in the remote URL

Every SSH connection to GitHub is made as the user `git`. A URL with your GitHub username in it fails with exactly this error[1]. Look at the remote:

```sh
git remote -v
```

An SSH URL looks like `git@github.com:OWNER/REPOSITORY.git`[6]. If yours has another user before the `@`, fix it:

```sh
git remote set-url origin git@github.com:OWNER/REPOSITORY.git
```

### 5. git runs with sudo

`sudo git pull` runs as root, and root does not use the keys you generated as yourself. GitHub's advice is not to use `sudo` with git at all[1].

### 6. An SSH URL on a server that has no key

A deploy script or CI job clones `git@github.com:...` on a machine where nobody ever set up a key, so it fails with the same message. That case has its own answer: a deploy key, or HTTPS with a token. Both are below.

## Fix: create a key, load it, add it to GitHub

**1. Generate an Ed25519 key**[3], with your GitHub email as the label. Press Enter for the default file and type a passphrase when asked:

```sh
ssh-keygen -t ed25519 -C "you@example.com"
```

On a legacy system without Ed25519 support, use `ssh-keygen -t rsa -b 4096` instead. GitHub no longer accepts DSA keys[3].

**2. Load it into the ssh-agent**[3]. On Linux:

```sh
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
```

On macOS, add this to `~/.ssh/config` so keys load into the agent and the passphrase is kept in the keychain (leave out `UseKeychain` if the key has no passphrase)[3]:

```text
Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519
```

and then:

```sh
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
```

**3. Add the public key to GitHub**[4]. Print it and copy the whole line:

```sh
cat ~/.ssh/id_ed25519.pub
```

On GitHub, open **Settings → SSH and GPG keys → New SSH key**, give it a title such as the machine's name, choose the authentication key type, paste the key and click **Add SSH key**. Only the `.pub` file goes to GitHub; the private key never leaves the machine.

**4. Test again** with `ssh -T git@github.com`. The greeting with your username means git will work too.

## The alternative: HTTPS with a token

If you do not want SSH on this machine, switch the remote to HTTPS[7]:

```sh
git remote set-url origin https://github.com/OWNER/REPOSITORY.git
```

`https://` URLs work on every repository and through firewalls and proxies[6]. On the next fetch, pull or push, git asks for a username and a password: the password is a personal access token, because GitHub removed password authentication for git[6]. A credential helper such as Git Credential Manager remembers it[6]. GitHub recommends fine-grained personal access tokens, which can be limited to specific repositories[8]. A token is a password in all but name: keep it out of the repository and out of shell history.

## On a server: use a deploy key

A server that only needs to pull one repository should not carry your personal key. GitHub's answer is a **deploy key**: an SSH key that grants access to a single repository. Its public half is attached to the repository instead of to a person, and its private half stays on the server[5]. Deploy keys are read-only by default; you can allow write access when you add one[5].

On the server, generate a key without a passphrase (`-f` names the file, `-N ""` sets an empty passphrase)[11]:

```sh
ssh-keygen -t ed25519 -f ~/.ssh/myapp_deploy_key -N "" -C "myapp server"
```

Then in the repository on GitHub: **Settings → Deploy keys → Add deploy key**, paste the contents of `myapp_deploy_key.pub`, and leave **Allow write access** off unless the server must push[5].

A deploy key cannot be reused for a second repository, so a server that pulls several repositories needs one key per repository and an alias for each in `~/.ssh/config`[5]:

```text
Host github.com-myapp
  Hostname github.com
  IdentityFile ~/.ssh/myapp_deploy_key
```

Clone through the alias, and SSH picks the right key:

```sh
git clone git@github.com-myapp:OWNER/myapp.git
```

Know the trade-offs GitHub lists: a deploy key usually has no passphrase, so whoever gets into the server has it; it does not expire; and it stays active when the person who created it leaves the repository[5]. For access across many repositories or organisations, GitHub recommends a GitHub App and its short-lived installation tokens instead[5].

## On Livops

Deploying from GitHub to Livops does not ask you to create or copy an SSH key: access goes through the GitHub App you install.

- **Connect GitHub.** In the **New project** dialog, click **Connect GitHub**. Livops is installed as a GitHub App and sees only the repositories you select; you choose which ones in GitHub itself, and can revoke access whenever you like.
- **Pick the repository and branch.** If you pick no branch, the repository's default branch is used. For a monorepo, give the folder the project lives in, such as `apps/web`.
- **Push to deploy.** Every `git push` to that branch starts a new deploy; pushes to other branches do not. If the build fails, the log shows why and the old version keeps running. The details are in [Ways to deploy](https://livops.dev/en/docs/deploy) and [Deploy from GitHub on every push](https://livops.dev/en/guides/deploy-from-github).
- **No GitHub?** GitLab works through a webhook you connect in the project settings, or drop the folder or a `.zip` straight into the browser.

What Livops does not fix: the error on your own laptop. To push to GitHub you still need a working SSH key or an HTTPS token, as above. And if you run your own VPS, a deploy key per repository is the right tool there. The **Account → SSH keys** page in the Livops cabinet is for something else: the SSH tunnel to your [databases](https://livops.dev/en/docs/databases), not for git.

A web app costs **39 credits a month**, a bot, worker or cron job **19**; see [Pricing](https://livops.dev/en/docs/pricing).

## Questions

**Do I need SSH to use GitHub at all?**

No. Every repository also has an HTTPS URL. Switch the remote with git remote set-url origin https://github.com/OWNER/REPOSITORY.git, and when git asks for a password, give it a personal access token, not your GitHub password.

**ssh -T git@github.com works, but git push still fails. Why?**

Git is not connecting the way your test did. Check git remote -v: the URL must start with git@github.com, not with your own username. And do not run git with sudo, because root does not use the keys in your home folder.

**Should I create an ed25519 or an RSA key?**

Ed25519. GitHub's instructions use ssh-keygen -t ed25519 and keep RSA with 4096 bits for legacy systems that do not support Ed25519. DSA keys are no longer accepted.

**Can one deploy key serve several repositories?**

No. GitHub does not let you reuse a deploy key for more than one repository. Create a key per repository and give each one its own Host alias in ~/.ssh/config on the server.

**Should I copy my personal SSH key to the server?**

Better not. A deploy key reaches a single repository and is read-only unless you allow write access, so a compromised server exposes one repository. GitHub suggests a GitHub App when you need finer control than that.

**Why does git keep asking for my key's passphrase?**

The key is not held by the ssh-agent. Add it with ssh-add. On macOS, put AddKeysToAgent and UseKeychain in ~/.ssh/config and add the key with ssh-add --apple-use-keychain so the keychain remembers the passphrase.

**Does Livops need an SSH key to read my repository?**

No. You click Connect GitHub and Livops is installed as a GitHub App that sees only the repositories you select. Every push to the chosen branch starts a deploy.

## Sources

1. [GitHub Docs — Error, Permission denied (publickey)](https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey). Checked 3 December 2026.
2. [GitHub Docs — Testing your SSH connection](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection). Checked 3 December 2026.
3. [GitHub Docs — Generating a new SSH key and adding it to the ssh-agent](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent). Checked 3 December 2026.
4. [GitHub Docs — Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account). Checked 3 December 2026.
5. [GitHub Docs — Managing deploy keys](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys). Checked 3 December 2026.
6. [GitHub Docs — About remote repositories](https://docs.github.com/en/get-started/git-basics/about-remote-repositories). Checked 3 December 2026.
7. [GitHub Docs — Managing remote repositories](https://docs.github.com/en/get-started/git-basics/managing-remote-repositories). Checked 3 December 2026.
8. [GitHub Docs — Managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens). Checked 3 December 2026.
9. [OpenSSH source — sshconnect2.c](https://raw.githubusercontent.com/openssh/openssh-portable/master/sshconnect2.c). Checked 3 December 2026.
10. [Git source — connect.c](https://raw.githubusercontent.com/git/git/master/connect.c). Checked 3 December 2026.
11. [OpenBSD manual — ssh-keygen(1)](https://man.openbsd.org/ssh-keygen.1). Checked 3 December 2026.
