Run SSH to set up this document: in Linux, The GitServer that uses SSH for shared access wants to control the permissions of UserProject and the read and write permissions such as branchtag, so Gitolite and other suites are required to assist. gitolite? SSH-basedgatekeeperforgitrepositories
Set up a Git Server using SSH for shared access in Linux
You want to control User/Project permissions and control braNcFor read/write permissions such as h/tag, you need to rely on Gitolite and other suites for assistance.
- GitOlite ? SSH-basEdKeep keeper for git repositories
This article mainly describes how to set up Gitolite. If you have already set up a Git Server for shared access in accordance with the above Article, and Gitolite also wants to use a git account for management, you need to change the settings as follows.
Note: This article uses the gitolite account for management and does not use the git account, so you do not need to make the following changes
- Vim/etc/Passwd
Git: x: 1000: 1000:/home/git:/usr/bin/git-shell
Change back
Git: x: 1000: 1000:/home/git:/bin/sh
- Mv/Home/git/. ssh/authorized_keys/home/git/. ssh/authorized_keys.bak
Prepare relevant materials
- System: Debian/Ubuntu Linux
- Server:ExAmple.com
- Project name: project_name
- Gitosis (Git) Repository location:/Var/lib/gitolite/repositories# Default location of Debian/Ubuntu Linux suite
- Group name: myteam
System kit installation
- Apt-get install gitolite git-core
- This message is displayed after the installation is complete: No adminkey given? Not initializing gitolite in/var/lib/gitolite.
- For relevant settings, see/etc/gitolite/example. conf,/etc/gitolite/example. gitolite. rc.
Generate an SSH Public Key
- Ssh-keygen-t rsa # generationId_ Rsa, id_rsa.pub
- Mv id_rsa ~ /. Ssh/# Place id_rsa IN ~ /. Ssh/internal.
- SCpId_rsa.pub example.com:/tmp/user1.pub # Drop id_rsa.pub to the Server. All public keys must be uploaded to the Server.
- Scp id_rsa.pub example.com:/tmp/admin. pub # the Administrator's key is the same as the user key, which is set to admin. pub here to avoid confusion in the following content.
Gitosis Server SETUP
- Ssh example.com # Git Server
- SuDo su? Gitolite
- Gl-SetUp/tmp/admin. pub# Import the Public key of the Administrator. Note:The file name is the account nameDo not use id_rsa.pub as the file name. We recommend that youUse "account. pub" as the file name
- Exit
Gitolite Server: Set Project and add account
- Gitolite project permissions/account management is managed using Git, Project name: gitolite-admin.git
- Git clone gitolite@example.com: gitolite-admin# Because Gitolite is managed with a gitolite-admin.git, so you need to grasp the changes, settings (all future management is also the case)
- CdGitolite-admin # You will see the following
- Conf/gitolite. conf # sets the file to set who can read and write the Repository of the project.
- Keydir # directory. Put the public key of each account. Name of the archive: user1.pub, user2.pub (user1, user2.. For the account name (File name = Account), It is recommended thatUse "account. pub" as the file name)
Set Project Permissions
- Cd gitolite-admin
- Vim conf/gitolite. conf # You will see the following, do not touch him, set your own Group/project name at the bottom.
Repo gitolite-admin
RW + = admin
Repo testing
RW + = @ all
- After this file is added/modified, commit + push is enough.
Create a project
- Git clone gitolite@example.com: testing # corresponding to gitolite. conf repo testing, the following message appears
Cloning into testing...
Warning: You appear to have cloned an empty repository.
- Cd testing
- TouchReadme
- GitDd.
- Git commit-m'add readme'
- Git push origin master
Add account
- Cd gitolite-admin
- Cp/tmp/user1.pub keydir/user1.pub # Please name it according to the actual account, do not get user1, user2
- Cp/tmp/user1.pub keydir/user1@machine.pub # If the same account, use the user@machine.pub
- Cp/tmp/user2.pub keydir/user2.pub
- Git add keydir/user1.pub keydir/user1@machine.pub keydir/user2.pub
- Git commit-m'add user1, user1 @ machine, user2 public key'
- Git push
Gitolite. conf more settings
The following is an excerpt from Gitolite's Git server construction? Authorized users create their own space (N Repository can be created under the User), which is not recorded here. For details, see section 2.4.3 of this article.
# From 2.3.1Basic authorization File Syntax
@ Admin = jiangxin wangsheng
Repo gitolite-admin
RW + = jiangxin
Repo ossxp/. +
C = @ admin
RW = @ all
Repo testing
RW + = @ admin
RW master = junio
RW + pu = junio
RW cogito $ = pasky
RW bw/= linus
-= Somebody
RW tmp/= @ all
RW refs/tags/v [0-9] = junio
# From 2.3.3ACL
Repo testing
RW + = jiangxin @ admin
RW = @ dev @ test
R = @ all
Gitolite. conf syntax description repo syntax
- Repo Syntax:<Permission> [Reference of zero or multiple regular expression batches] = <user> [<user>...]
- Each Command must specify a permission. The permission can use any of the following keywords:C, R, RW, RW +, RWC, RW + C, RWD, RW + D, RWCD, RW + CD
- C: Establish
- R: Read
- RW: Read + write
- RW +: Read + write + force Push on the rewind commit
- RWC: The authorization command defines regex (branch and tag defined by regex.
- RW + C: Same as above, C is a reference that allows the establishment of a regex pair (branch, tag, etc)
- RWD: This authorization command can be used only when regex (branch and tag defined by regex) is defined in the authorization command.
- RW + D: Same as above. D is a reference that allows you to delete matching regex (branch, tag, etc)
- RWCD: This authorization command can be used only when regex (branch and tag defined by regex) is defined in the authorization command.
- RW + CD: C is a reference that can be paired with regex (branch, tag, etc.), D is a reference that can be deleted with regex (branch, tag, etc)
- -: The data cannot be written but can be read.
- NOTE: If regex does not start with refs/, the refs/heads/
Group
- @ All indicates the meaning of everyone.
- @ Myteam user1 user2: user1, user2 belong to the group of myteam
Common
Command
All of the following operations are performed in the gitolite-admin.git
- Add account
- Cp/tmp/user1.pub keydir/user1.pub # Note:The file name must be "account. pub"
- Add Project
- Vim conf/gitolite. conf # Add repo, for example:
Repo testing
RW @ all
- Git clone gitolite@example.com: testing
- Set Project
- Vim conf/gitolite. conf # Add a repo and set the read/write group and User Permissions
Related Documents
- How does Gitolite build a Git server? Gitolite is recommended.