Aliyun linux-centos System-Build git server
Summary of steps:
1. Install git
First confirm that the server is installing Git
Enter the command in Xshell:$ rpm-qa git
The result is that the following is installed:
Install git if it is not installed
Enter in Xshell:$ yum Install git
2. Create a git user to run the GIT service:
Enter in Xshell:$ sudo adduser git
At this point in the root directory of the Aliyun server:/home folder add a folder git
Create a file at this level to hold the client user's public key:/home/git/.ssh/authorized_keys
On the local client's git bash, by command:
$ ssh-keygen-t rsa-c "youremail@example.com"
Or
$ ssh-keygen
command to generate public key, default in C disk: User/.ssh id_rsa.pub file is the public key, with Notepad open copy paste into the/home/git/.ssh/authorized_keys file of the service.
3. Build git warehouse in server
Create a new Git folder at the server root that is dedicated to storing the warehouse
The warehouse is created and initialized with the following code, with an empty warehouse:
$ sudo chown-r git:git sample.git
The next code must be executed once, possibly by getting push permissions and preventing the user from modifying the workspace, which cannot be pushed locally to the GIT server if it is not performed:
$ sudo chown-r git:git sample.git
4. Prohibit git users from logging on to the shell
For security reasons, the GIT user you created does not allow you to log on to the shell, which can be done by editing the/etc/passwd file. Locate a line similar to the following:
git:x:1001:1001:,,,:/home/git:/bin/bash
To
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
This way, git users can normally use git through SSH, but cannot log on to the shell because the Git-shell that we specify for git users automatically exits each time they log on.
5. Cloning the Sample.git warehouse built on the GIT server
In local git bash, navigate to a folder that holds the cloned files, and enter the following clone command:
$ git clone Git@xxx.xxx.xxx.xxx:/xxx/git/sample.git
The Clone Server Warehouse command is in the following format:
git clone git@ server public IP: Repository store on server path
6. Associate a local git warehouse with a git server warehouse
Creating a new sample warehouse locally and initializing it requires the same name as the warehouse on the GIT server.
The repository built on the GIT server is sample.git, not local. Git.
Both the server and the local warehouse are available, and the following steps are used to correlate the two:
In local git bash, navigate to the local warehouse and enter and execute the following code:
$ git remote Add sample Git@xxx.xxx.xxx.xxx:/xxx/git/sample.git
In Git bash enter:$ git remote-v can view the remote Git repository associated with the local git warehouse.
In git bash input:$ git push-u sample master pushes local warehouse main branch to remote git repository, first push needs plus-U.
Later push is directly used in git bash input:$ git push sample master can.
Thank you for reading, I hope to help you, thank you for your support for this site!