Git: git clone – fatal: unable to fork and RSA key fingerprint

By | 10/23/2020
 

We have a Docker image with Git client installed.

The task is to automatically clone a repository when running a container from this image.

git clone – fatal: unable to fork

When running the git clone command in a container from this Docker image it fails with the “unable to fork” error:

/ # git clone git@github.com:projectname/backend-services.git
Cloning into 'backend-services'...
fatal: unable to fork

The cause is that git uses SSH for authentication here (git@github.com), but we have no ssh client installed in the image:

/ # ssh
sh: ssh: not found

Install it:

/ # apk update
/ # apk add openssh

The authenticity of host ‘github.com’ can’t be established

Another issue when automating git clone – it’s asking to confirm the RSA key from the github.com host:

The authenticity of host ‘github.com (140.82.121.4)’ can’t be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?

To solve this – need to add its public key to the ~/.ssh/known_hosts file.

Use ssh-keyscan for this:

/ # ssh-keyscan github.com >> ~/.ssh/known_hosts
github.com:22 SSH-2.0-babeld-1a846ed2
github.com:22 SSH-2.0-babeld-1a846ed2
github.com:22 SSH-2.0-babeld-1a846ed2

And now clone the repository:

/ # git clone git@github.com:projectname/backend-services.git
...
remote: Total 5115 (delta 96), reused 169 (delta 56), pack-reused 4871
Receiving objects: 100% (5115/5115), 846.55 KiB | 3.00 MiB/s, done.
Resolving deltas: 100% (2826/2826), done.

Done.