1

I am running a script in the ubuntu vm and I am trying to clone from my private repo.

I added keygen in my script for ssh clone but I get an error. This is what my script looks like and the error

echo ">> Checking out $GITHUB_PAGES_BRANCH branch from $GITHUB_PAGES_REPO"
cd /tmp/helm/publish
mkdir -p "$HOME/.ssh"
ssh-keyscan -H github.com >> "$HOME/.ssh/known_hosts"
echo "CLONING:::::"
git clone -b "$GITHUB_PAGES_BRANCH" "git@github.com:$GITHUB_PAGES_REPO.git" .
echo "CLONED :::::"
ls

I get this error in my console

>> Checking out test-branch branch from getME/demo
# github.com:22 SSH-2.0-babeld-cXXXXX
# github.com:22 SSH-2.0-babeld-cXXXXX
# github.com:22 SSH-2.0-babeld-cXXXXX
# github.com:22 SSH-2.0-babeld-cXXXXX
# github.com:22 SSH-2.0-babeld-cXXXXX

CLONING:::::
Cloning into '.'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

CLONED :::::

I am running this script on Github Actions.

Any help is appreciated.

King
  • 1,885
  • 3
  • 27
  • 84
  • 1
    This looks like it should generally work (provided the `$HOME/.ssh/known_hosts` file is new each time so that it doesn't contain an old stale fingerprint). However, this sequence effectively just disables host key checking entirely, so you might want the more direct `-o StrictHostKeyChecking=no` (or equivalent in `$HOME/.ssh/config`). You can pass options to ssh through Git using `core.sshCommand` or the environment variable `$GIT_SSH_COMMAND`. – torek Aug 12 '22 at 01:07

1 Answers1

0

Trying a git clone -c core.sshCommand='ssh -Tv' clone -b "$GITHUB_PAGES_BRANCH" "git@github.com:$GITHUB_PAGES_REPO.git" would hep seeing what is going on.

See this action as an example of an actual SSH clone working

        run: |
          mkdir -p ~/.ssh/
          echo "$GIT_SSH_RSA_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan github.com >> ~/.ssh/known_hosts

The chmod is important.


Note March 2023:

"GitHub has updated its RSA SSH host key"


VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250