How to Fix Gitea SSH Port Configuration Error
In this tutorial, you'll learn about How to Fix Gitea SSH Port Configuration Error. We cover key concepts, practical examples, and best practices.
Gitea SSH clone returns ssh: connect to host port 22: Connection refused or port 22 is already in use — the Gitea built-in SSH server conflicts with the system SSH daemon.
The Problem
$ git clone git@git.example.com:user/repo.git
Cloning into 'repo'...
ssh: connect to host git.example.com port 22: Connection refused
Step-by-Step Fix
Step 1: Change Gitea to use a different SSH port
In app.ini:
[server]
SSH_DOMAIN = git.example.com
SSH_PORT = 2222
SSH_LISTEN_PORT = 2222
START_SSH_SERVER = true
Step 2: Update docker-compose port mapping
ports:
- "2222:2222"
- "3000:3000"
Step 3: Update the clone URL
git clone ssh://git@git.example.com:2222/user/repo.git
# Or config SSH to use port 2222:
# ~/.ssh/config
Host git.example.com
Port 2222
Step 4: Disable built-in SSH and use system SSH
[server]
START_SSH_SERVER = false
SSH_PORT = 22
Then add the Gitea SSH public key to /home/git/.ssh/authorized_keys.
Prevention Tips
- Use a port above 1024 to avoid requiring root
- Set
DISABLE_SSH = falseonly if you need built-in SSH - Configure SSH key-based authentication in Gitea user settings
- Test SSH connectivity with
ssh -v -p 2222 git@git.example.com
Common Mistakes with ssh port
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad
These mistakes appear frequently in real-world GITEA code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro