Skip to content

Instantly share code, notes, and snippets.

@dnhn
Last active May 7, 2025 00:25
Show Gist options
  • Save dnhn/48be17340963ba9a1f75e05ab05a075f to your computer and use it in GitHub Desktop.
Save dnhn/48be17340963ba9a1f75e05ab05a075f to your computer and use it in GitHub Desktop.
Git server on AWS EC2 Amazon Linux 2023

Important

sudo must be executed as root user.

sudo yum update -y
sudo yum install git -y

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html

https://repost.aws/knowledge-center/new-user-accounts-linux-instance

# root user

sudo mkdir /srv/git
sudo chown -R git:git /srv/git

# git user

mkdir /srv/git/repo.git
cd repo.git
git init --bare

User:

git clone git@address:/srv/git/repo.git
sudo yum install git-daemon -y
sudo mkdir /srv/git/public

Command

git daemon --verbose --base-path=/srv/git/public --export-all --reuseaddr --detach /srv/git/public

System service (recommended)

sudo vim /etc/systemd/system/git-daemon.service
sudo systemctl enable git-daemon

User

git clone git://address/public.git
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install gitweb git-instaweb -y
cd path/to/repo.git
git instaweb --httpd=httpd

# http://ipaddress:1234

/etc/gitweb.conf

our $projectroot = "/srv/git/public";

Path

/etc/httpd/conf.d/gitweb.conf

Alias /git /var/www/git
sudo systemctl restart httpd

# http://ipaddress/git

Root

/etc/httpd/conf.d/gitweb.conf

<VirtualHost *:80>
  ServerName gitserver
  DocumentRoot /var/www/git

  <Directory /var/www/git>
  …
  </Directory>
</VirtualHost>
sudo systemctl restart httpd

# http://ipaddress
sudo dnf install -y certbot python3-certbot-apache
sudo systemctl daemon-reload
sudo systemctl enable --now certbot-renew.timer
sudo certbot --apache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment