Setting Up a Simple Gogs Git Server with Systemd on Linux
This guide walks through installing Gogs, creating a start‑up script, configuring a systemd service, launching the server, checking its status, creating repositories via the web UI or command line, and pushing code with saved credentials, all on a Linux host.
First, create a start‑up script for Gogs at /usr/local/gogs/start.sh with the following content:
#!/bin/bash
/usr/local/gogs/gogs web > /tmp/gogs.log 2>&1Make the script executable:
chmod +x /usr/local/gogs/start.shNext, define a systemd unit file /usr/lib/systemd/system/gogs.service :
[Unit]
Description=gogs
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/gogs/start.sh
User=root
[Install]
WantedBy=multi-user.targetReload the daemon and start the service:
systemctl daemon-reload
systemctl restart gogsVerify that Gogs is listening (default port 3000) using netstat -nltp or similar tools.
Check the server log for successful startup:
tail -f /usr/local/gogs/log/gogs.logAfter confirming the service is running, you can create a new repository either through the Gogs web interface (screenshots omitted) or via the command line. To create a repository from the command line, run:
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin http://192.168.20.40:3000/hahashen/devops.git
git push -u origin masterTo push an existing local project, follow these steps:
mkdir -pv /soft/shell
cd /soft/shell
git init
vim hahage.sh # add your files
git add *
git commit -m "hahashen"
git remote add origin http://192.168.20.40:3000/hahashen/devops.git
git push -u origin masterIf you want to avoid entering a password each time, edit the repository’s .git/config file and embed the credentials in the URL, e.g.:
[remote "origin"]
url = http://hahashen:[email protected]:3000/hahashen/devops.gitAfter updating the config, pushing again will not prompt for a password.
Cloning the repository without Jenkins can be done with:
git clone http://192.168.20.40:3000/hahashen/devops.gitOnce cloned, you can inspect the files in the working directory.
The article concludes by inviting readers to continue with a Jenkins‑Git integration tutorial.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.