Skip to content

Fix known_hosts not working (#14) - #19

Open
simtrami wants to merge 1 commit into
yesolutions:masterfrom
simtrami:fix_known_hosts
Open

Fix known_hosts not working (#14)#19
simtrami wants to merge 1 commit into
yesolutions:masterfrom
simtrami:fix_known_hosts

Conversation

@simtrami

Copy link
Copy Markdown

Use absolute path for git config options

Replace ~ with /github/home when used for a file path in the options of a git configuration. For some reason, git does not resolve it and ignores the errors (probably just defaults too) as the files do not exist.
Passing it ~/.ssh/id_rsa was not an issue though as it already is the default private key file ssh uses.

Tested and approved

I temporarily published it to the actions marketplace in order to try it with my non-working workflow and it fixed it.

Replace `~` with `/github/home` when used for a file path in the options of a git configuration. For some reason, git does not resolve it and ignores the errors (probably just defaults) when the files do not exist.
Passing it `~/.ssh/id_rsa` was not an issue though as it is the default SSH PK file.
@simtrami simtrami mentioned this pull request Aug 21, 2021
@simtrami

Copy link
Copy Markdown
Author

BEFORE MERGING

You might want to put the resolution of ~ in a variable and concatenate it instead of hard coding /github/home as I did: Github could change the home path and therefore break the script anytime.

@ldeluigi

Copy link
Copy Markdown

@spyoungtech

marcvanandel added a commit to kadaster-labs/secured-sparql-endpoint-subgraph that referenced this pull request Dec 11, 2023
@marcvanandel

Copy link
Copy Markdown

Probably the .github/workflows/main.yml should be updated to check whether this feature is actually operational by replacing:

        GIT_SSH_NO_VERIFY_HOST: "true"

with:

        GIT_SSH_KNOWN_HOSTS: ${{ secrets.GIT_SSH_KNOWN_HOSTS }}

Comment thread entrypoint.sh
if [[ "${GIT_SSH_KNOWN_HOSTS}" != "" ]]; then
echo "${GIT_SSH_KNOWN_HOSTS}" > ~/.ssh/known_hosts
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=~/.ssh/known_hosts"
git config --global core.sshCommand "ssh -i /github/home/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=/github/home/.ssh/known_hosts"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 New user of the action here and running into this issue.

To simplify things, I would suggest not setting the -i and -o UserKnownHostsFile arguments at all. The action is already writing the key and known_hosts to the default locations, so the default settings should be sufficient.

Suggested change
git config --global core.sshCommand "ssh -i /github/home/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=/github/home/.ssh/known_hosts"
git config --global core.sshCommand "ssh -o IdentitiesOnly=yes"

Of course, to ignore host fingerprints, you will still set StrictHostKeyChecking below:

        git config --global core.sshCommand "ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no"

In both cases, you should be able to drop the -i and -o UserKnownHostsFile.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: In addition, you don't need the -o IdentitiesOnly=yes option either. So, you'd only need to define core.sshCommand in the case where you want to ignore fingerprints.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true because the home directory is resolved differently by the ssh and by the shell.

In the shell the home directory is resolved to /github/home, by ssh it's resolved to /root.

@Malix-Labs

Copy link
Copy Markdown

Any update ?

cynicsketch added a commit to cynicsketch/mirror-action that referenced this pull request Oct 26, 2025
@ffflorian

Copy link
Copy Markdown

Ping @spyoungtech

stewalec added a commit to stewalec/mirror-action that referenced this pull request Feb 19, 2026
@scientress

Copy link
Copy Markdown

I just stumbled over this bug and bug-fix and it would be really great if this could be megred/resolved.

scientress added a commit to scientress/mirror-action that referenced this pull request Jun 16, 2026
scientress added a commit to scientress/mirror-action that referenced this pull request Jun 16, 2026
…cotry is resolved diffrently

closes: yesolutions#14
supersedeas: yesolutions#19

Details:
In the shell ~ and the home dir are resolved to /github/home, but when ssh resolves the home directory it /root.
This causes the default search paths to be wrong (/root/.ssh/known_hosts instead of /github/home/.ssh/known_hosts).
The idenity file path is automatically expanded by the shell because it's an argument on it's own.
But for the known_hosts file path this is not the case because the argument is an assignment, so the shell doesn't expand it
scientress added a commit to scientress/mirror-action that referenced this pull request Jun 16, 2026
…cotry is resolved diffrently

closes: yesolutions#14
supersedeas: yesolutions#19

Details:
In the shell the home directory is resolved to `/github/home`, but when ssh resolves it, it resolves `/root`.
This causes the default search paths to be wrong (`/root/.ssh/known_hosts` instead of `/github/home/.ssh/known_hosts`).
The idenity file path is automatically expanded by the shell because it's an argument on it's own.
But for the known_hosts file path this is not the case because the argument is an assignment, so the shell doesn't expand it
NECOtype added a commit to NECOtype/mirror-action that referenced this pull request Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants