Issue
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 ?
Solution
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.
Answered By - alzee
Answer Checked By - David Marino (JavaFixing Volunteer)