Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

386
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda