Git clone fails if you have a custom SSH Port

563 views Asked by At

I have changed the SSH Port on my Rocky Linux 9.1 machine.As a result git clone and git pull hangs. There is no error even with verbose .

git clone [email protected]:videojs/video.js.git

cat /root/.ssh/config

Host github.com
Hostname github.com
Port 22

I have also tried the following config but its not working

Host github.com
Hostname ssh.github.com
Port 443
User git

Edit

ssh -vvT [email protected]
OpenSSH_8.7p1, OpenSSL 3.0.1 14 Dec 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug2: checking match for 'final all' host github.com originally github.com
debug2: match not found
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug1: configuration requests final Match pass
debug1: re-parsing configuration
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf
debug2: checking match for 'final all' host github.com originally github.com
debug2: match found
debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
debug2: resolving "github.com" port 22
debug1: Connecting to github.com [192.30.255.113] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type 0
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.7
debug1: Remote protocol version 2.0, remote software version babeld-2fb663a1
debug1: compat_banner: no match: babeld-2fb663a1
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to github.com:22 as 'git'
debug1: load_hostkeys: fopen /root/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
1

There are 1 answers

0
macoo On

I just can give you a single clue because I don't know much about ssh.

On MacBook, Before I modified Host github.com to Host ssh.github.com, ssh test log was the same as yours. After modification, never the less, ssh -Tv [email protected] tested OK, but git still uses port 22.

Host ssh.github.com
   User git
   Port 443
   HostName ssh.github.com
   IdentityFile ~/.ssh/id_rsa
# ssh test ok
ssh -T -p 443 [email protected]
"Hi MoeexT! You\'ve successfully authenticated, but GitHub does not provide shell access."

# ----------------------------------------

# git fetch or push still uses port 22
git fetch -v
"kex_exchange_identification: Connection closed by remote host
Connection closed by 20.205.243.166 port 22
fatal: Could not read from remote repository.

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

On win10-WSL-ubuntu2204, I didn't change that Host, its still OK.

GitHub reference: Using SSH over the HTTPS port