Git Clone/Fetch Freezing SSH: Troubleshooting
In this article, we will cover some of the most common issues faced when trying to clone or fetch from a Git repository using SSH and provide actionable solutions. If you've ever found yourself saying, "I've been trying to clone/fetch SSH, but it suddenly stopped working," then this article is for you.
1. Check SSH Configuration
First, ensure that your SSH configuration is set up correctly. To check this, run the following commands:
$ ssh -T [email protected]
or
$ ssh -T [email protected]
You should see an authentication message similar to the following:
Hi USER! You've successfully authenticated, but GitHub does not provide shell access.
If you're facing any issues, generate a new SSH key and add it to your GitLab account:
$ ssh-keygen -t ed25519 -C "[email protected]"
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_ed25519
$ cat ~/.ssh/id_ed25519.pub
Copy the output and paste it into your GitLab account's "SSH Keys" section.
2. Clear Git Cache
Sometimes, cloning or fetching from a Git repository might fail because of cached credentials. Clear the Git cache using the following command:
$ git config --global --unset credential.helper
3. Disable SSH Keepalive
SSH can stop responding due to network issues or timeouts. You can adjust the SSH configuration to send keepalive packets to avoid this issue:
Host gitlab.com
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 30
4. Check Network Connectivity
If you're behind a firewall or using a restricted network, some SSH ports might be blocked. To resolve this issue, use an HTTPS connection in Git:
$ git clone https://gitlab.com/username/repo.git
5. Use Git Configuration Tweaks
Git can sometimes face performance issues while fetching large repositories. To improve fetch performance, consider tweaking Git's configuration:
$ git config --global fetch.fallbackToCLone false
Additionally, you can adjust the pack size to avoid freezing during fetch:
$ git config --global http.postBuffer 524288000
6. Debug Using Strace (Linux Only)
$ git clone 2>&1 | strace -f -o strace.out
Then, inspect the strace.out file to detect system call errors:
$ grep -E -i 'connection|timeout|reset|refused|ssl|tls' strace.out
- Check SSH configuration and ensure that SSH keys are added to your repository provider's account
- Clear the Git cache to avoid credential caching issues
- Configure SSH keepalive packets to avoid timeouts
- Consider using HTTPS when facing network connectivity restrictions
- Tweak Git configuration options to improve fetch performance
- Use strace (Linux only) for debugging Git SSH issues
References
- GitLab SSH Setup: https://docs.gitlab.com/ee/ssh/
- Git SSH Troubleshooting: https://git-scm.com/book/en/v2/Git-on-the-Server-Troubleshooting
- Strace Manual: https://linux.die.net/man/1/strace