- Go (1.18+ recommended)
- Git installed on the host machine.
Clone this repository or create the base directory structure:
mkdir -p git-server/{templates,static,repos}
cd git-serverNote: Update the BaseStoragePath constant at the top of main.go to match the absolute path to your repos/ directory.
SSH is a two-way street. The server needs its own cryptographic identity to prove to connecting clients that it is not a Man-in-the-Middle attacker. Run this inside your project root to generate a password-less Ed25519 key strictly for the server:
ssh-keygen -t ed25519 -f server_ed25519 -q -N ""To allow your personal machine to push code, you need to add your personal public key to the server's VIP list.
- Create the authorized keys file:
touch authorized_keys - Copy your local machine's public key (usually found at
~/.ssh/id_ed25519.pubor~/.ssh/id_rsa.pub). - Paste the contents directly into the
authorized_keysfile.
Initialize your Go module and download the required cryptographic packages:
go mod init gitserver
go get golang.org/x/crypto/sshStart the dual-headed server (SSH + HTTP):
go run main.goYou should see logs indicating that the SSH server is listening on 0.0.0.0:2222 and the Web UI is running on http://localhost:8080.
Because the server supports auto-provisioning, you do not need to create repositories on the server manually. Just push!
In a completely separate terminal window, initialize a new project and push it to your server:
mkdir my-project
cd my-project
git init
echo "# Hello World" > README.md
git add .
git commit -m "Initial commit"
# Add the remote (format: ssh://localhost:2222/<namespace>/<repo-name>.git)
git remote add origin ssh://localhost:2222/yash/my-project.git
# Push to the server
git push origin mainNote: On your first connection, your terminal will ask if you trust the host fingerprint. Type yes to accept the server_ed25519 key we generated in Step 2.
git clone ssh://localhost:2222/yash/my-project.gitOpen your web browser and navigate to http://localhost:8080. You will see your dashboard and can click through the repositories to view the raw code extracted from the Git database.
This project is a highly capable core engine. To scale this into an enterprise-grade platform like GitHub or GitLab, the following architectural upgrades are recommended:
- Current State: Reads a flat
authorized_keysfile into memory. - Production State: Replace
os.ReadFilein thePublicKeyCallbackwith a PostgreSQL connection. Query auserstable by public key fingerprint to route connections dynamically without restarting the server.
- Current State: Git commands execute under the permissions of the OS user running the Go binary.
- Production State:
- Run the Go binary under a highly restricted, dedicated Linux user (e.g.,
git). - Implement repository-level permissions (Read/Write access checks) in the Go routing logic before wiring the
exec.Commandstreams.
- Run the Go binary under a highly restricted, dedicated Linux user (e.g.,
- Current State: The Web UI on port 8080 is public to anyone on the network.
- Production State: Implement JWT or Session-based authentication on the
net/httproutes, linking Web UI sessions to the database users.
- Current State: Go serves HTTP directly.
- Production State: Place the web server behind Nginx or Caddy to handle SSL/TLS termination (HTTPS), static asset caching, and request rate-limiting.
- Current State: Spawns an
os/execprocess for every Web UI click to read files. - Production State: Integrate
libgit2(viagit2go) to read the Git object database directly in memory, drastically reducing process overhead for the Web visualizer.