{"id":3958,"date":"2021-01-30T08:09:56","date_gmt":"2021-01-30T08:09:56","guid":{"rendered":"https:\/\/linuxways.net\/?p=3958"},"modified":"2021-01-30T08:10:04","modified_gmt":"2021-01-30T08:10:04","slug":"how-to-setup-git-server-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-setup-git-server-on-ubuntu-20-04\/","title":{"rendered":"How to Setup Git Server on Ubuntu 20.04"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>When working with the Git version control system, you have many choices such as Github, Bitbucket, or Gitlab. If you want to avoid depending on third-party providers, you can run your own Git server.<\/p>\n<p>Setting up a Git server by yourself allows you to no longer be restricted by public providers\u2019 free plans such as maximum repository size, creating unlimited private repositories, and so on.<\/p>\n<p>This tutorial will show you the way to set up a Git server on your Ubuntu 20.04 machine.<\/p>\n<h2>Installing Git server<\/h2>\n<p>Firstly, update your packages list by running:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>To install Git, run the following command:<\/p>\n<pre>$ sudo apt install git<\/pre>\n<p>Verify that Git was successfully installed on your system:<\/p>\n<pre>$ git version<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"116\" class=\"wp-image-3959\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-507.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-507.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-507-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-507-1024x77.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-507-768x58.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>It\u2019s highly recommended that you should create a new Linux user for managing the Git repositories, run:<\/p>\n<pre>$ sudo useradd -m -r -U -d \/home\/git-repos git<\/pre>\n<p>The home directory of git user is located at \/home\/git-repos. To increase security, we\u2019ll create an ssh key to log in to the git user.<\/p>\n<p>Switch to the log-in session of git user by running:<\/p>\n<pre>$ sudo su - git<\/pre>\n<p>To create the SSH directory and file for holding the authorized ssh key for git user, run the following commands:<\/p>\n<pre>$ mkdir -p ~\/.ssh<\/pre>\n<pre>$ chmod 700 ~\/.ssh<\/pre>\n<pre>$ touch ~\/.ssh\/authorized_keys<\/pre>\n<pre>$ chmod 600 ~\/.ssh\/authorized_keys<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"216\" class=\"wp-image-3960\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-508.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-508.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-508-300x42.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-508-1024x144.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-508-768x108.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Once, the server was successfully set-up, it\u2019s time to create a new git repository:<\/p>\n<pre>$ git init --bare ~\/linuxways.git<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"146\" class=\"wp-image-3961\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-509.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-509.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-509-300x29.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-509-1024x97.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-509-768x73.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<h2>Configuring Git repository<\/h2>\n<p>Now, you have to add your local user\u2019s public SSH key to the authorized_keys file of the git user.<\/p>\n<p>If you already have generated an SSH key for your local user, you can skip the following step:<\/p>\n<pre>$ ssh-keygen -t rsa<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"802\" class=\"wp-image-3963\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-510.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-510.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-510-300x157.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-510-1024x535.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-510-768x401.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Now, you can retrieve your public SSH key by running:<\/p>\n<pre>$ cat .ssh\/id_rsa.pub<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"296\" class=\"wp-image-3964\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-511.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-511.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-511-300x58.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-511-1024x197.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-511-768x148.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Copy the above public SSH key then paste it into the authorized_keys file of the git user.<\/p>\n<p>On your local Ubuntu 20.04 machine, assuming that you already had an unversioned directory, for example, ~\/go. Change the current directory to it:<\/p>\n<pre>$ cd ~\/go<\/pre>\n<pre>$ git init .<\/pre>\n<p>Next, you have to add a git remote to track your local repository on Git server:<\/p>\n<pre>$ git remote add origin git@git-server-ip-address:linuxways.git<\/pre>\n<p>Verify that your Git server was successfully installed and configured, run the following command:<\/p>\n<pre>$ cd ~\/go<\/pre>\n<pre>$ touch README<\/pre>\n<pre>$ git add .<\/pre>\n<pre>$ git commit -m \"Add file Readme\"<\/pre>\n<pre>$ git push origin master<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"1052\" class=\"wp-image-3965\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-512.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-512.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-512-300x205.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-512-1024x701.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-512-768x526.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we\u2019ve described the detailed steps of installing and configuring a Git server.<\/p>\n<p>If you encounter any problems, please let me know.<\/p>\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction When working with the Git version control system, you have many choices such as Github, Bitbucket, or Gitlab. If you want to avoid depending on third-party providers,&hellip;<\/p>","protected":false},"author":23,"featured_media":3962,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[100],"class_list":["post-3958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=3958"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3958\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/3962"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=3958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=3958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=3958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}