diff --git a/server/git/git.md b/server/git/git.md new file mode 100644 index 0000000..aa929d8 --- /dev/null +++ b/server/git/git.md @@ -0,0 +1,56 @@ +# Git Server + +`su -` Switch to root for most of this + +## Make a git user + +`adduser git` + +Adduser if prefered to useradd, but in case + +`useradd git` +`mkdir /home/git` +`chown -R git:git /home/git` + +## Make the git directory +`mkdir /srv/git` This can got anywhere, but this makes sense +`cd /srv/git` + +### Give ownership of the directory +`chown -R git:git /srv/git` + +## Add a repo +`git init --bare ` + + +## How to clone, commit, etc. from your server + +### Add existing branch +Add remote to existing Repo +`git init` +`git remote add ssh://git@:/srv/git/` \* +`git push (--set-upstream/-u) ` + +### \* Remove the port +Don't use the ! You don't need to if your port is 22 (default ssh). +If you've changed it to be more secure, then instead change your ssh config!! + +`.ssh/config` add + + Host + Port + +### Clone the branch +Clone is the same, but with `git clone`, not `git remote add ` + +## Add SSH keys + +As the git user! +`su git` if you're still logged in as root :) + +Either ssh-copy-id from your PC, connecting to the server as git@. +Or +Make an authorised keys file and add keys manually +`mkdir .ssh && chmod 700 .ssh` +`touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys` +Then copy keys into `.ssh/authorized_keys` diff --git a/server/git/gitweb.md b/server/git/gitweb.md new file mode 100644 index 0000000..f591db7 --- /dev/null +++ b/server/git/gitweb.md @@ -0,0 +1,51 @@ +# GitWeb + +A web GUI for your repositories +This is assuming an install of git, and nginx + +## Install gitweb +Debian already has this as a package. +If your server distro doesn't... + +`sudo apt install gitweb fcgiwrap` + +## Setup a webpage + +### Create a new nginx site +`vim /etc/nginx/sites-available/gitweb` + +Add the following +`server { + listen 80 ; + listen [::]:80 ; + server_name git. www.git. ; + + location /index.cgi { + root /usr/share/gitweb/; + include fastcgi_params; + gzip off; + fastcgi_param SCRIPT_NAME $uri; + fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + } + + location / { + root /usr/share/gitweb/; + index index.cgi; + } +}` + +#### Copy new site to site-enables + +`ln -s /etc/nginx/sites-available/gitweb /etc/nginx/sites-enabled/` + +### Change default gitweb location + +`vim /etc/gitweb.conf` + +Amend the line containing `/var/lib/git` to `/srv/git` + + +Reload nginx +`systemctl reload nginx` + diff --git a/server/git/gitweb_nginx b/server/git/gitweb_nginx new file mode 100644 index 0000000..e90ab8a --- /dev/null +++ b/server/git/gitweb_nginx @@ -0,0 +1,72 @@ +# https://stackoverflow.com/questions/6414227/how-to-serve-git-through-http-via-nginx-with-user-password/17553364#answer-17553364 +server { + listen 80 ; + listen [::]:80 ; + + if ($host = git.aney.co.uk) { + return 301 https://$host$request_uri ; + } + + if ($host = www.git.aney.co.uk) { + return 301 https://$host$request_uri ; + } + return 404; +} + +server { + listen 443 ssl; + listen [::]:443; + server_name git.aney.co.uk ; + + root /usr/share/gitweb/; + + # Remove auth_* if you don't want HTTP Basic Auth + #auth_basic "example Git"; + #auth_basic_user_file /etc/nginx/.htpasswd; + + # static repo files for cloning over https + location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { + root /srv/git/; + } + + # requests that need to go to git-http-backend + location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { + root /srv/git/; + + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; + fastcgi_param PATH_INFO $uri; + fastcgi_param GIT_PROJECT_ROOT $document_root; + fastcgi_param GIT_HTTP_EXPORT_ALL ""; + fastcgi_param REMOTE_USER $remote_user; + include fastcgi_params; + } + + # Remove all conf beyond if you don't want Gitweb + try_files $uri @gitweb; + location @gitweb { + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi; + fastcgi_param PATH_INFO $uri; + fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; + include fastcgi_params; + } + + #location /index.cgi { + #root /usr/share/gitweb/; + #include fastcgi_params; + #gzip off; + #fastcgi_param SCRIPT_NAME $uri; + #fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; + #fastcgi_pass unix:/var/run/fcgiwrap.socket; + #} + + #location / { + #root /usr/share/gitweb/; + #index index.cgi; + #} + + ssl_certificate /etc/letsencrypt/live/git.aney.co.uk/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/git.aney.co.uk/privkey.pem; # managed by Certbot +} +