Skip to content

bug: git-clone did not parse and add port to ssh-keyscan command #1073

Description

@LazyGeniusMan

Issue

PR #942 add feature to add repo url to known host, but it only parse the host and did not parse the port when running ssh-keyscan command. This make the known host added for port 22 instead.

My use case is using self hosted gitea/forgejo, because port 22 already used by the host for ssh into the host machine I use port 2222 instead for the git ssh. The repo URL is something like this:

ssh://git@forgejo.domain.tld:2222/LazyGeniusMan/test-repo.git

The current parsing is :

SSH_HOST=$(echo "$REPO_URL" | sed -E 's|^(ssh://)?([^@/]+@)?([^:/]+).*|\3|')

The result for repo URL above is : forgejo@domain.tld

Then the value used in:

if KNOWN_HOST_ENTRY=$(ssh-keyscan -H -t rsa,ecdsa,ed25519 "$SSH_HOST" 2> /dev/null) && [ -n "$KNOWN_HOST_ENTRY" ]; then

Proposed Fix

  1. Parse the port from ssh repo url
  2. Pass the -p arg to ssh-keyscan command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions