Server-side configuration
1. Install git
2, create a new user, can only be used to upload code, but not through SSH login, such as git users
AddUser git
Chsh-s $ (command-v git-shell) git
Replace bash with Git-shell so that git users can't log in via SSH
This step will have a warning that Git-shell is not in the shell list, do not worry.
3, add the SSH public key, add the client's public key in/home/git/.ssh/authorized_keys, one line at a.
If there are no files, you can create a new
Mkdir/home/git/.ssh
Touch/home/git/.ssh/authorized_keys
The method by which the client generates the public key is Ssh-keygen,
Windows in the C:\Users\ user name \.ssh\ directory, open id_rsa.pub
4. Initialize an empty git repository
Cd/var
Git init--bare sample.git
Chown-r Git:git Sample.git
This step is to allow the directory to be modified by git users, or "Permission denied" error will occur.
Client
1, you can git clone
git clone [email protected] Server:/var/sample.git the file path on the server
or SSH, recommended ssh, easy to set the port number
git clone ssh://[email protected] Server: Port number/var/sample.git
Refer to Article 1, article 2
Linux build git server