Npm run deploy failing: permission denied(publickey)

Hello! I am trying to put my React projects on Github Pages with npm run deploy. Everything goes fine with the first stages of npm run build and react scripts build. But then when it gets to this part it fails:

> gh-pages -d build

Cloning into 'C:\Users\User\path\to\file\react-drum-pad\node_modules\.cache\gh-pages\!EdenSweden!react-drum-pad.git'... Permission denied (publickey).
fatal: Could not read from remote repository.

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

npm ERR! errno 1
npm ERR! react-drum-pad@0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-drum-pad@0.1.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2021-09-11T22_47_38_527Z-debug.log

When I try to debug my ssh key by entering ‘ssh -vT’, it prints this:

OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Connecting to [IP address] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\User/.ssh/id_rsa type 0      
debug1: identity file C:\\Users\\User/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\User/.ssh/id_dsa type -1     
debug1: identity file C:\\Users\\User/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\User/.ssh/id_ecdsa type -1       
debug1: identity file C:\\Users\\User/.ssh/id_ecdsa-cert type -1  
debug1: identity file C:\\Users\\User/.ssh/id_ed25519 type -1     
debug1: identity file C:\\Users\\User/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\User/.ssh/id_xmss type -1        
debug1: identity file C:\\Users\\User/.ssh/id_xmss-cert type -1   
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1      
debug1: Remote protocol version 2.0, remote software version babeld-e995f6d1
debug1: no match: babeld-e995f6d1
debug1: Authenticating to as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: MAC: <implicit> compression: none
debug1: kex: client->server cipher: MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:[host key here]
debug1: Host '' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\User/.ssh/known_hosts:2
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: C:\\Users\\User/.ssh/id_rsa RSA SHA256:[key here]
debug1: Will attempt key: C:\\Users\\User/.ssh/id_dsa 
debug1: Will attempt key: C:\\Users\\User/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\User/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\User/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<,,,,,,,,,,,,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\User/.ssh/id_rsa RSA SHA256:[key here]       
debug1: Server accepts key: C:\\Users\\User/.ssh/id_rsa RSA SHA256:[key here] 
debug1: read_passphrase: can't open /dev/tty: No such file or directory
Enter passphrase for key 'C:\Users\User/.ssh/id_rsa': [i enter the passphrase]
debug1: Authentication succeeded (publickey).
Authenticated to ([ip address]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi EdenSweden! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3400, received 2868 bytes, in 0.6 seconds

So clearly my SSH key is working. I even created a whole new SSH key and that one still isn’t allowing me to complete npm run deploy. What do I do from here? I have followed the troubleshooting steps in the Github documentation, but to no avail.
Could it be because it never asks for my passphrase when running gh-pages -d build?
The SSH folder on my computer has no config file, if that means anything. Just id_rsa,, and known_hosts.

Thank you sooo much for your help. I have been stuck for days. Most online explanations seem to assume I already know Git/Node and don’t explain things clearly at all.

Just in case, have you checked that you are able to pull down the git repository from GitHub? Try to clone into a new folder just to make sure things are hooked up correctly. If you’re able to clone the project then it should mean that your SSH credentials are set up correctly. If that’s the case then it’s possible that npm doesn’t have permission on your computer to read the files in .ssh/.

If you installed npm with sudo then it could cause issues with regards to file permissions.

Thank you for your response. I just tested git clone ‘ssh address’ and it worked. So that’s not the problem. I also never used sudo. Any idea how to check if npm has permission to read the files in /.ssh? I have been using other npm functions just fine (npm start, etc.). It just doesn’t like it when I run gh-pages -d build.

Solution! I did a couple things:

  • Updated to the latest versions of node.js and npm.

  • Navigated to the project I wanted to deploy on my computer, right clicked, selected Git Bash Here and typed ‘npm run deploy’ + enter. Then it actually prompted me for my passphrase, unlike in my code editor terminal.
    Thanks for the help in any case.

Edit: after some issues with installing github pages on npm version 7.23.0, I had to downgrade back to npm version 6.14.15.

Yay! Glad it worked out.