A GitHub Actions SSH deploy step cannot log in to the server
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remainShort 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.
Fix it fast
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.com2Match what you see, then jump to its fix
- 1
The 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
The 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
ssh -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
ssh -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
- 1
What does the error look like?
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remainssh: 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/*.yml2Fix
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 logConfirmed by docs.github.com
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_key2Fix
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_key3Verify
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 jobsConfirmed by github.com
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 12Fix
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
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
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
Security
AuthenticationException: your certificate validation callback returned false
System.Security.Authentication.AuthenticationException
This message means a validation callback was installed, yours or one a library added, and it returned false.
3 causes, each with a fixSecurity
SSH to an EC2 instance fails with Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
ec2-user@ec2-203-0-113-25.compute-1.amazonaws.com: Permission denied (publickey).
On EC2 this error almost always means the instance did not accept your key for that user.
3 causes, each with a fixSecurity
gcloud init cannot finish the sign-in step
Enter authorization code
gcloud init signs in through a browser.
3 causes, each with a fixSecurity
SSH to GitHub asks to confirm the host, or hangs on that prompt
ED25519 key fingerprint is SHA256:
SSH has never seen github.com from this machine, so it asks you to trust the server key.
2 causes, each with a fixSecurity
A GUI program over SSH says it cannot open the display
cannot open display:
ssh must forward X11 and the remote sshd must allow it.
3 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fix