Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

A GitHub Actions SSH deploy step cannot log in to the server

Errorssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

Short answer

The runner reached your server but the server refused the login. First check that the key secret really arrives in the job: an unset or fork-blocked secret is an empty string. Then check the pasted key is complete, the server accepts its algorithm, and its public half sits in authorized_keys.

  • Applies to appleboy/ssh-action, GitHub Actions, OpenSSH 9, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    From your own machine, log in with the exact private key you stored in the secret, in verbose mode. If this fails too, the problem is the key or the server, not the workflow.

    ssh -v -i ~/.ssh/deploy_key deploy@your-server.example.com
  2. 2Match what you see, then jump to its fix

    1. 1The same key works from your laptop, but the action fails on pull requests from forks, on Dependabot runs, or right after you renamed the secret.The secret is empty in that jobFix
    2. 2The key secret exists, but the login fails and the first or last line of the key is missing.The private key was pasted incompleteFix
    3. 3ssh -v from your machine shows the key offered and then rejected, and the key is an older RSA key on a newer Ubuntu server.The server does not accept the key's algorithmFix
    4. 4ssh -v ends with the key offered and no acceptance, and the login works with another key.The public key is not where the server looks, or the folder is too openFix

What does the error look like?

  • ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
  • ssh: handshake failed: ssh: unable to authenticate

Cause 1 of 4

The secret is empty in that job

1Check

GitHub does not pass secrets to workflows triggered from a forked repository or by Dependabot, and a secret that is not set evaluates to an empty string. List the secret names the repository actually has and compare them with the name in the workflow.

# repository Settings > Secrets and variables > Actions: note the names
grep -n "secrets\." .github/workflows/*.yml

2Fix

Use the exact secret name, set it at the right level (repository, environment or organization), and run the deploy only on events that receive secrets, such as a push to your main branch.

- uses: appleboy/ssh-action@v1
  with:
    host: ${{ secrets.SSH_HOST }}
    username: ${{ secrets.SSH_USER }}
    key: ${{ secrets.SSH_PRIVATE_KEY }}

3Verify

Re-run the job from a push to the main branch and read the step log.

# Actions tab: open the new run and read the SSH step log

Confirmed by docs.github.com

Did this fix it?

Cause 2 of 4

The private key was pasted incomplete

1Check

The action expects the whole key, from the BEGIN line to the END line, both included. A key copied through a terminal width or a chat tool often loses the first or last line.

head -n 1 ~/.ssh/deploy_key
tail -n 1 ~/.ssh/deploy_key

2Fix

Copy the file again in one piece and store it as the secret. On macOS pbcopy puts it on the clipboard; on Linux use xclip.

pbcopy < ~/.ssh/deploy_key
# Linux: xclip < ~/.ssh/deploy_key

3Verify

The first line reads -----BEGIN OPENSSH PRIVATE KEY----- and the last line reads -----END OPENSSH PRIVATE KEY-----. Re-run the workflow.

# Actions tab: Re-run failed jobs

Confirmed by github.com

Did this fix it?

Cause 3 of 4

The server does not accept the key's algorithm

1Check

The action's own troubleshooting notes say Ubuntu 20.04 and later may need ssh-rsa allowed in the OpenSSH daemon, and that an ED25519 key avoids the question. Look at the key type first: the command prints ssh-rsa or ssh-ed25519.

ssh-keygen -y -f ~/.ssh/deploy_key | cut -d ' ' -f 1

2Fix

Generate a dedicated ED25519 deploy key, store its private half as the secret and append its public half to the server.

ssh-keygen -t ed25519 -a 200 -C "deploy@github-actions" -f ~/.ssh/deploy_key
cat ~/.ssh/deploy_key.pub | ssh user@your-server.example.com 'cat >> .ssh/authorized_keys'

3Verify

Log in with the new key from your machine, then re-run the workflow.

ssh -i ~/.ssh/deploy_key user@your-server.example.com 'echo ok'

Confirmed by github.com

Did this fix it?

Cause 4 of 4

The public key is not where the server looks, or the folder is too open

1Check

The action's notes say that, depending on the SSH version, the public key may need to be in .ssh/authorized_keys2, with .ssh at mode 700 and the file at mode 640. Check what is on the server.

ssh user@your-server.example.com 'ls -ld .ssh; ls -l .ssh; ls -l .ssh/authorized_keys2'

2Fix

If the plain authorized_keys is ignored on that host, put the deploy key's public line in authorized_keys2 and set the modes the notes name.

ssh user@your-server.example.com 'chmod 700 .ssh && chmod 640 .ssh/authorized_keys2'

3Verify

A key-only login succeeds from your machine.

ssh -i ~/.ssh/deploy_key user@your-server.example.com 'echo ok'

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Give the workflow its own deploy key instead of reusing a personal key, and keep one secret per purpose.
  • Deploy only from push events on protected branches, where secrets are available.
  • Prefer ED25519 keys for new deploy keys.
  • After rotating a key, test it by hand with ssh -i before updating the secret.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.