One, nagging two sentences
Under normal circumstances, the opportunity to build a git server is relatively small, and the only purpose of building a git server is multi-person collaboration. github is a typical git server, but its free hosting code is open source. If you don't want to open source, you need to pay a protection fee to github.
Suppose one day you and your friends want to start a non-open source commercial project, and need to use version control, then we need to build our own git server. Before that, we have to have a server that can be accessed by our friends, which reminds me of the server I bought last year to build a ladder. VirMach , the service provider of the United States, bought it during the event. It cost 6 US dollars a year, which is very cost-effective. In order to buy it, I also specially went to apply for a dual currency credit.
But now it seems that many service providers support Alipay payment, which also leads to serious out of stock of this cheap server, that is to say, you can't buy it! ! !
The cheapest vps launched by VirMach now costs $1 a month and $10 a year, and the configuration is worse than mine.
And my server is about to expire on May 11th this year. I suddenly thought of the issue of renewal. In this case, I feel that I can't renew it. After all, I bought it during the event period. But I never imagined that I received the renewal bill from VirMach a few days ago, and it was still $6, or $6! ! ! I paid the bill without hesitation. It's really the conscience of the US emperor. If you want to let domestic profiteers, I feel that you will definitely not be able to renew the fee.
2. Enter the topic
The first step is to install git, I am using the ubuntu server, so just use the apt-get command,
sudo apt-get install git
The second step is to create a git user specifically for the git service,
sudo adduser git
The third step is to switch to the git user. The reason for this step is that some files to be created and edited later should preferably belong to the git user.
su git
The fourth step , initialize an empty git repository,
Suppose we build the git repository in the /home/git/srv
directory , then we cd into this directory and execute the following command,
git init --bare sample.git
Note: git repositories on the server usually end with .git
The fifth step , create a certificate login,
The git service can be logged in through ssh, so it is necessary to collect the ssh public key of the small partner. The public key is usually located in a .ssh/id_rsa.pub
file . For details on getting the public key, please refer to this article on GitHub's SSH key configuration under Windows . After getting the partner's public key, we add it to the .ssh/authorized_keys
file , one per line.
If this file does not exist in the system, create it, as follows,
cd /home/git/
mkdir .ssh
touch .ssh/authorized_keys
Here our git server is established, then let's use the clone command on the client to try it, as follows:
git clone git@server:/home/git/srv/sample.git
Note: The server is your server address, which can be directly IP or domain name.
The easiest problem to encounter in this process is the problem of file permissions. For example, the execution of push prompts that the permissions are not enough.
If you do not switch to git, the created repository will not belong to the git user. We use the chown command to change it, as follows:
chown -R git:git sample.git
In addition, the read and write permissions are changed to 777 for simple and rude, and we still change the insurance point to 764, as follows:
chmod -R 764 sample.git
Scan the code to follow me to learn more, have a good weekend! ^_^