Using HTTP in Git is the permission of Webserver, and using SSH is the permission of each account. (permission issues may occur in the object directory of Git.) If multiple users share the permission, there are several methods to use SSH: Create a new account (git) for unified management by the git account (commitpush) and so on.
Using HTTP in Git is the permission of the Web server, and using SSH is the permission of each account. (permission issues may occur in the Git object directory)
SSH can be used to share multiple users:
- Create a new account (Git), Managed by git accounts (commit/push), etc.
- Use gitosis for Management (gitosis can set "who" can access this project ).
- Use gitolite for Management (gitolite can set who can access this project, and can set which bra can only be accessedNcH and other paths)
What is this article? Idea.
Prepare relevant materials
- System: Debian/Ubuntu Linux
- Server:ExAmple.com
- Project name: project_name
- Git Repository:/var/cache/git
System kit installation
Generate an SSH Public Key
- Ssh-keygen-t rsa# GenerateId_ Rsa, id_rsa.pub
- MvId_rsa ~ /. Ssh/# Place id_rsa IN ~ /. Ssh/internal.
- SCpId_rsa.pub example.com:/tmp/id_rsa_user1.pub # Drop id_rsa.pub to the Server, and all public keys must be uploaded to the Server.
Git Server settings
- Ssh example.com
- ADdUser git -- disablEd-Password # create a git account and execute all the actions by git to avoid permission issues.
- Su-Git # Switch to git Permissions
- Cd;Mkdir. Ssh
- Add your public key (the problem of remote git login will be solved later)
- Cat/Tmp/id_rsa_user1.pub> ~ /. Ssh/authorized_keys
- Cat/tmp/id_rsa_user2.pub> ~ /. Ssh/authorized_keys
- ? : Commit/push will retain the name of the original commit user, not git
Create Git Repository
- Ssh example.com
- Su-git
- Mkdir-p/var/cache/git/project_name.git
- Cd/var/cache/git/project_name.git
- Git init -- bare -- shared
Add information to Git Repository
In your computer, either of the following two methods can be used:
- Git clone git@example.com:/var/cache/git/project_name.git
- Cd project_name
- Vim test.txt
- Git add.
- Git commit-m'add test.txt'
- Git push origin master
Or
- Mkdir project_name
- Cd project_name
- Git init
- Git add.
- Git commit-m'initial commit'
- Git remote add origin git@example.com:/var/cache/git/project_name.git
- Git push origin master
Avoid Git Account Login (security issues)
- Vim/etc/Passwd# Modify/bin/sh =>/usr/bin/git-shell. git-shell can only perform git operations, but cannot Login.
Set
git:x:1000:1000::/home/git:/bin/sh
Change
git:x:1000:1000::/home/git:/usr/bin/git-shell
You can.
Frequently Used instruction notes
- Clone: git clone git@example.com:/var/cache/git/project_name.git
- Commit & Push: git push
- Command for the first time Commit/Push: git push origin master