How to Setup Git Daemon Server?
Things to Know Before Setting Up Git Daemon
We'll set up a daemon to serve Git repositories. For quick and unauthenticated access to your Git data, this is a popular option. Because this is not an authenticated service, anything you offer over this protocol will be visible to everyone on the network.
If you're running this on a server that's not behind your firewall, you should only use it for projects that are open to the public.
You could use it for projects requiring read-only access from a large number of individuals or machines (continuous integration or build servers), and you would not want to add an SSH key for each of them if the host you're running it on is inside your firewall.
In any event, setting up the Git protocol is quite simple. Basically, you'll want to run this command as a daemon:
git daemon —reuseaddr —base-path=/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git
The —reuseaddr option allows the server to resume without waiting for previous connections to time out, while the —base-path option allows users to clone projects without having to specify the complete path, and the path at the end instructs the Git daemon where to seek for repositories to export. If you're using a firewall, make a hole in it at port 9418 on the machine you're using to set this up.
You can daemonize this operation in a variety of ways, depending on your operating system.
You can use systemd for this because it is the most widely used init system among recent Linux distributions. Simply create a file with the following contents in /etc/systemd/system/git-daemon.service.
Start Git Daemon is a [unit] description.
[Service] ExecStart=/usr/bin/git daemon —reuseaddr —base-path=/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git/srv/git
You'll see that the Git daemon is launched as both a group and a user. Make any necessary changes and double-check that the specified user exists on the system. Also, verify that the Git binary is located at /usr/bin/git and, if necessary, modify the location.
Finally, you'll execute system enable git-daemon to have the service start automatically on boot, and you'll be able to start and stop it with system start git-daemon and systemc stop git-daemon, respectively
How to Setup Git Daemon Server?
1. Adding a Git User and Uploading Keys
When you hear the terms "uploading" or "managing" keys, you're referring to the process of adding new keys to the.ssh/authorized keys file. You can save as many public keys as you want in this file, and there are several methods for accessing them.
Copying and pasting the key from your local computer to the server is one option.
You can also use the SSH command to copy the key to the server:
ssh-copy-id -i /.ssh/key user@ ssh-copy-id -i /.ssh/key user@ user@ user@ user@ user@ user
2. Creating Git Repositories in "Bare" Form
After deciding which directory will host your remote repositories, you may begin building repositories as directories ending in.git. The extension is crucial since it distinguishes between directories that contain files.
Create a directory like this to create a repository called "website":
mkdir website.git website.git website.git website.git website.git website.
Then, using the cd command, go into the directory:
cd website.git && &&&&&&&&&
Create a "bare" Git repository once within the directory:
—bare git init
Git will now be able to detect website.git when you add it as a remote repository (as seen below).
"There is nothing in this repository yet, but I want this directory (website.git) to serve as a remote repository," you tell Git when you create the —bare git repository.
Your Remote Repository Should Be Included
So far, you've set up a git user account, a basic repository in your desired directory, and SSH key authentication for the git user.
All that's left is to tell your local Git installation about the new repository.
git remote copied to git@server:/path/to/website should be included to the origins list.
Let's take a closer look at this command.
The git remote add command adds a repository from a remote location. The new repository is named in the "origin" portion. You are allowed to use whatever name you choose. you are not required to use "origin," but it is a standard naming method.
The remainder of the command specifies the location to the bare Git repository you created on the server.
Pushing your project to the new repository is the final step. If you're pushing the "master" branch, for example, the comand will look like this:
git push origin master clone
That concludes our discussion. You've figured out how to make your own Git repository on your own server.
While you're here, you might also want to learn how to "checkout" (or, in other words, copy) files from your repository to a specific server directory. This is a fantastic approach to publishing files to a website's document root or a specified directory.