{"id":1728,"date":"2021-04-08T01:23:20","date_gmt":"2021-04-08T01:23:20","guid":{"rendered":"https:\/\/dft.wiki\/?p=1728"},"modified":"2026-04-21T13:34:38","modified_gmt":"2026-04-21T17:34:38","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>Git server is not but the SSH server and the same Git app used on the client-side.<\/p>\n<p>It is strongly recommended to use SSH-Keys while using SSH especially if it is protecting the source codes of the company.<\/p>\n<p>If you have any doubt 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>Change 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 the users that will be allowed to work with the repositories to the file <strong>\/home\/git\/.ssh\/authorized_keys<\/strong> each one in a different line.<\/p>\n<p>At this point follow the post to <strong>Increasing Security with Fail2Ban<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=401\">Link<\/a>] to protect the SSH against password brute force attacks.<\/p>\n<p>Create the repositories inside the server:<\/p>\n<pre>ssh git@server\r\ngit init --bare repository1.git\r\nexit<\/pre>\n<p>Clone the remote repository to local:<\/p>\n<pre>git clone git@server:repository1.git<\/pre>\n<p>Create a file and pull 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 Pull\"\r\ngit push origin master<\/pre>\n<p>The lines in gray will only be used on the very first time.<\/p>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>Automate Git operations in multiple repos simultaneously with MyRepos [<a href=\"https:\/\/github.com\/RichiH\/myrepos\">Link<\/a>]. For example, pull the all 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>\u00a0[<a href=\"https:\/\/dft.wiki\/?p=1484\">Link<\/a>].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git server is not but the SSH server and the same Git app 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":8,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1728\/revisions"}],"predecessor-version":[{"id":5488,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1728\/revisions\/5488"}],"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}]}}