Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git permission denied inside Docker container

I am using a shell script as the part of Jenkinsfile to run database migration. The shell script attempts to clone a repository after setting an entry in known_hosts file. I am doing the following :

    #!/bin/bash

    set -e

    # Workaround old docker images with incorrect $HOME
    # check https://github.com/docker/docker/issues/2968 for details
    if [ "${HOME}" = "/" ]
    then
      export HOME=$(getent passwd $(id -un) | cut -d: -f6)
    fi

    mkdir -p ~/.ssh

    echo '
    github.com ssh-rsa KEY
  ' >> ~/.ssh/known_hosts

    git clone [email protected]:Organization/migrations.git /tmp/database-migrations

   Execute Migration

This gives me an error which is

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

How can solve this ?

BTW when I check the known hosts file, I am seeing an entry has been added to the file with an IP which is 192 range (local IP). Is this creating the problem ?

like image 500
Happy Coder Avatar asked Aug 31 '25 22:08

Happy Coder


1 Answers

Not because the known_hosts file. As it said, I think it's your private key.

Have you copy the right private key into your container? 'cause I didn't see it in your script.

You can test your key by typing:

ssh -T [email protected]

I beleive you'll see the same result.

And you can check this link Error: Permission denied (publickey) on github.

like image 59
alzee Avatar answered Sep 03 '25 17:09

alzee