Skip to content

How to Fix Gitea SSH Port Configuration Error

DodaTech Updated 2026-06-24 2 min read

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 = false only 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

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to 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

### Why does Gitea's SSH server conflict with the system SSH?

By default Gitea tries to bind to port 22, which the system SSH daemon (sshd) already uses. Either change Gitea to a different port, or disable Gitea's built-in SSH server and use SSH keys via authorized_keys.

How do I make SSH clones work without specifying the port?

Add a Host block in ~/.ssh/config: Host git.example.com\n Port 2222. Then git clone git@git.example.com:user/repo.git works without the explicit port.

Does Gitea support SSH on port 443?

Yes, if you tunnel SSH over HTTPS. Set SSH_PORT = 443 and ensure your reverse proxy routes SSH traffic correctly. This is useful when port 22 is blocked by a firewall.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro