1. Install git
sudo yum install Git
2. Querying the GIT version
Git–version
Installation is successful if displayed
3. Create a git user to run the GIT service
AddUser git
4. Go to the directory and initialize the GIT repository
sudo git init--bare sample.git
Git creates a bare repository with no workspaces, because the GIT repository on the server is purely for sharing, so you don't let users log on to the server directly to the workspace, and the Git repositories on the server usually end up with. Git. Then, change owner to git:
Chown-r Git:git Sample.git
5. Configure password-free SSH login
On gitclient_01, we use the command: ssh-keygen–t RSA to generate the key, as
After completion, in the. SSH directory, we can see the Id_rsa and id_rsa.pub files, id_rsa.pub as the public key, we scp/home/git/.ssh/id_rsa.pub gitserver:/home/by command Git copies the public key generated on the gitclient_01 to the Gitserver.
On Gitserver We first look at whether Authorized_kesys files exist under the/home/git/.ssh directory,
If not, you can create this file and folder from Touch Authorized_keys.
After the Authorized_keys is created, append the contents of the public key id_rsa.pub copied on the gitclient_01 to the Authroized_keys, note that it is appended to the file, and you can use the command cat/home/git/id_ Rsa.pub>>/home/git/.ssh/authorized_keys.
When the above content is complete, we can use the command SSH gitserver to complete the login without password in gitclient_01.
6. Disable Shell logon:
For security reasons, the GIT user created in the second step is not allowed to log in to the shell, which can be done by editing the/etc/passwd file. Find a line similar to the following:
git:x:1001:1001:,,,:/home/git:/bin/bash
Switch
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
7. Cloning a remote repository:
Now, you can clone the remote repository with the git clone command and run it on your own computer:
$ git clone [email protected]:/srv/sample.git
Enter Password login
Cloning into ' sample ' ...
Warning:you appear to has cloned an empty repository.
Linux CentOS git Build