{"id":1728,"date":"2021-04-08T01:23:20","date_gmt":"2021-04-08T01:23:20","guid":{"rendered":"https:\/\/dft.wiki\/?p=1728"},"modified":"2026-06-08T23:08:12","modified_gmt":"2026-06-09T03:08:12","slug":"private-git-server-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=1728","title":{"rendered":"Private Git Server on Ubuntu"},"content":{"rendered":"<p>A Git server is simply an SSH server running the same Git application used on the client side.<\/p>\n<p>It is strongly recommended to use SSH keys when using SSH, especially when protecting company source code.<\/p>\n<p>If you have any doubts, read the post <strong>Setting Up SSH Keys<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=423\">Link<\/a>].<\/p>\n<p>Preparing the environment:<\/p>\n<pre>sudo apt update &amp;&amp; sudo apt upgrade -y\r\nsudo apt install git -y\r\nsudo adduser git<\/pre>\n<p>Switch to the new account:<\/p>\n<pre>su git\r\ncd ~\r\nmkdir .ssh\r\ntouch .ssh\/authorized_keys\r\nchmod 700 .ssh\r\nchmod 600 .ssh\/authorized_keys<\/pre>\n<p>Copy the public keys (<strong>\/home\/<span style=\"color: #ff0000;\">user1<\/span>\/.ssh\/id_rsa.pub<\/strong>) from all users who will be allowed to work with the repositories into the file <strong>\/home\/git\/.ssh\/authorized_keys<\/strong>, one per line.<\/p>\n<p>At this point, follow the post <strong>Increasing Security with Fail2Ban<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=401\">Link<\/a>] to protect SSH against brute force attacks.<\/p>\n<p>Create repositories on the server:<\/p>\n<pre>ssh git@server\r\ngit init --bare repository1.git\r\nexit<\/pre>\n<p>Clone the remote repository locally:<\/p>\n<pre>git clone git@server:repository1.git<\/pre>\n<p>Create a file and push it to the server:<\/p>\n<pre>touch README.md\r\ngit add .\r\n<span style=\"color: #808080;\">git config --global user.email \"user@example.com\"<\/span>\r\n<span style=\"color: #808080;\">git config --global user.name \"Your Name\"<\/span>\r\ngit commit -m \"First Push\"\r\ngit push origin master<\/pre>\n<p>The lines in gray are only needed the first time.<\/p>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>Automate Git operations across multiple repos simultaneously with MyRepos [<a href=\"https:\/\/github.com\/RichiH\/myrepos\">Link<\/a>]. For example, pull all of them at once:<\/p>\n<pre>sudo apt install myrepos -y\r\ncd repositoryDirectory\r\nmr register\r\nmr run git pull<\/pre>\n<p>Read more about <strong>Working with GitHub Repositories<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=1484\">Link<\/a>].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Git server is simply an SSH server running the same Git application used on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-1728","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1728"}],"version-history":[{"count":9,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1728\/revisions"}],"predecessor-version":[{"id":5749,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1728\/revisions\/5749"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}