0

Attempting to run the following for a deploy script in node

I'm using node-ssh to ssh onto a server and run a git pull, the user I'm using has a deploy key setup for this repo (it works if I run these commands manually on the server)

import { NodeSSH } from 'node-ssh'

await ssh.connect({
    host: process.env.SSH_HOST,
    username: process.env.SSH_USERNAME,
    password: process.env.SERVER_PASSWORD,
})

await ssh.execCommand(`git pull`, {
    onStdout: (out) => console.log(out.toString('utf8')),
    onStderr: (out) => {
      console.error(out.toString('utf8'))
      throw out.toString()
    },
    cwd: '/path-to-my-repo',
})

but the above errors with the following

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('[email protected]: Permission denied (publickey).\r\n')

The deploy key does have a passphrase, but ssh-agent has already been launched with that identity added. If I run git pull as this user on the server, I don't get prompted for the password.

Is there some configuration for node-ssh I'm missing that will give it access to this key?

2
  • Does this answer your question? connecting ssh server with private key in node js Commented Dec 1, 2023 at 16:29
  • @Zak no I can connect to the server absolutely fine, but when executing git pull on the server, it errors Commented Dec 1, 2023 at 23:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.