Permission Denied (Publickey). The Key Is RIGHT THERE.

Solvedauthenticationlinuxssh17 replies · 427 views · started
Accepted solution by Cleo Larsen — been there man in CI, private keys pasted as secrets often lose teh trailing newline or get CRLF line endings, make sure the key file ends…
  1. trying to SSH from WSL2 into a freshly built Ubuntu VM and i get:

    This app can't run on your PC

    This app can't run on your PC
    
    To find a version for your PC, check with the
    software publisher.
    

    Permission denied (publickey). I added my public key to authorized_keys, double-checked its the right one, even regenerated it once... password login is disabled sooo i cant get in any other way... what did i do wrong?

    Ive checked the key fingerprint against teh one on teh server and they look the same. Im stuck outside a box i need to fix today, with notihng but this error. Any debugging approach would be very welcome.

    facepalm

    4
  2. hmmm which user are u connecting as, and whose authorized_keys did teh key go into??

    0 1 helpful
  3. oh ive been there lol newer OpenSSH versions disable ssh-rsa singatures using SHA-1 by default... very old clients or libraries (some older CI tools) may only offer that, so the server refuses.. ;) prefer an ed25519 key, or upgrade teh client. worked for me anyway 🤷

    13 1 helpful
  4. ok so run the client in verbose mode first:

    ssh -vvv user@host
    

    Look for Offering public key: lines. if ur key is never offered, teh client isnt using it: pass -i ~/.ssh/id_ed25519 or set IdentityFile in ~/.ssh/config... if its offered and rejected, teh server side is the problem.

    1 2 helpful
  5. pro tip: write down what u change... i didnt and had to redo ssh from scratch fingers crossed 🤞

    5 12 helpful
  6. unrelated but anyone else's coffee machine also judging them today

    0 1 helpful
  7. ok update: did what @vikp386 said and its fine now

    6 1 helpful
  8. wait what idk man that sounds like bad advice tbh but hey ymmv

    2 0 helpful
  9. ok so sshd is strict about permisisons (StrictModes yes). on the server: chmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys, and the home directory must not be group- or world-writable, ownership must be the user, not root.

    1 2 helpful
  10. ahh classic check the server log while you try to connect: sudo journalctl -u ssh -f (or -u sshd on RHEL family, /var/log/auth.log on older Debian/Ubuntu). It says exactly why: bad ownership, wrong user, key type not accepted. hope that helps :)

    14 2 helpful
  11. ok so honestly just reset teh BIOS and save yourself the pain, same issue here on my work pc, driving me crazy worked for me anyway 🤷

    2 0 helpful
  12. ps how is this thread still going lmao

    0 2 helpful
  13. Watch the username. Cloud images use default users like ubuntu, ec2-user, admin or debian. connecting as root or your own name with a key thats only in the default users authorized_keys fails with exactly this error. lmk how it goes

    2 0 helpful
  14. @leap822 did u ever fix it??

    13 0 helpful
  15. Accepted solution

    been there man in CI, private keys pasted as secrets often lose teh trailing newline or get CRLF line endings, make sure the key file ends with a newline and has 600 permissions, or the client silently skips it. good luck man!

    0 10 helpful
  16. @quiet_owl dude the CI secret was missing its final newline. Fixed it and teh deploy step connects again. Thanks everyone! thank u thank u thank u

    1 2 helpful

Reply to this topic

Sign in or create an account to reply.