Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

391
Views
simple-git: SSH authentication example using simple-git

How to clone a repository with SSH using simple-git?

I'm trying to clone using this code

const git: SimpleGit = simpleGit();
const sshUri = 'git@..........'
const localPath = '/usr/workspace';
git
 .clone(
   sshUri,
   localPath
 ).then((data) => {
    console.log('success');
 }).catch((err) => {
     console.log(err);
 });

But I am getting an exception

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If your git repo is private, you will need to generate SSH key and add this key to your GIT account.

  • To generate SSH Key: https://docs.github.com/en/authentication/connecting-to-github-with-ssh
  • Add your SSH to git account: You can find it here https://github.com/settings/keys

Code example

    private async cloneRepo() {

        const gitSSH = 'FILL YOUR SSH GIT ADDRESS';
        const sourceDir = path.resolve(`${os.tmpdir()}/${this.projectKey}`);
        const sshKnownHosts = path.resolve(`${process.cwd()}/settings/ssh/known_hosts`)
        const sshKey = path.resolve(`${process.cwd()}/settings/ssh/id_ed25519`)

        const GIT_SSH_COMMAND = `ssh -o UserKnownHostsFile=${sshKnownHosts} -o StrictHostKeyChecking=no -i ${sshKey}`;

        console.log(sourceDir);

        const git: SimpleGit = simpleGit()
            .env('GIT_SSH_COMMAND', GIT_SSH_COMMAND)
            .clean(CleanOptions.FORCE);

        await git.clone(gitSSH, sourceDir, ['-b', 'YOUR-BRANCH-NAME', '--single-branch'])
            .then(() => console.log('finished'))
            .catch((err) => console.error('failed: ', err));
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!