git-shell - 新的存储库 [英] git-shell - New repositories
问题描述
我有一个专用的 git
用户和存储库
的服务器我试图使用 git-shell
method 允许我的开发人员在几个项目上工作。
I have a server with a dedicated git
user and repositories
I'm trying to use the git-shell
method to allow my devs to work on several projects.
我即将更改我的 git
user到 git-shell
如果我这样做,我将无法再与标准shell进行连接(这就是主意) 。
I'm about to change the shell of my git
user to git-shell
If I do that, I won't be able to connect with a standard shell anymore (that's the idea).
问题:那么我将如何创建新的存储库?
Question: So how will I create new repositories ?
有没有每次与一个sudoer连接,并创建repo然后chown它?
Will I have each time to connect with a sudoer and create the repo then chown it ?
推荐答案
我会每次都要连接一个sudoer并创建repo然后chown它?
Will I have each time to connect with a sudoer and create the repo then chown it ?
是的,您可以在文章 Git Local Repository Setup Guide 通过 Rami Al-Ghanmi( alghanmi
):
Repository Setup&首先,我们创建git用户并为SSH公钥身份验证设置帐户,并且不进行终端登录。
Yes, you can see an example in the article "Git Local Repository Setup Guide" by Rami Al-Ghanmi (alghanmi
):
$ b这意味着,git帐户无法使用密码登录(仅通过PKA),并且没有正常的shell访问权限。 相反,它将使用一个特殊的git shell和一组有限的命令。
#Create git user account
sudo adduser --shell $(which git-shell) --gecos 'git version control' --disabled-password git
#Add git user to the appropriate groups
sudo usermod -a -G www-data git
sudo usermod -a -G developers git
#Setup authorized_keys file for access
sudo mkdir -p /home/git/.ssh
sudo touch /home/git/.ssh/authorized_keys
sudo chmod 600 /home/git/.ssh/authorized_keys
sudo chmod 700 /home/git/.ssh
#Copy the git-shell-commands to get limited shell access
sudo cp -r /usr/share/doc/git/contrib/git-shell-commands /home/git/
sudo chmod 750 /home/git/git-shell-commands/*
#Fix permissions
sudo chown -R git:git /home/git/
添加您的 SSH生成密钥到授权密钥列表。您可以为所有想要访问的用户重复此步骤。
Add your SSH generated key to the authorized key list. You can repeat this step for all users you wish to give access to
cat ~/.ssh/id_rsa.pub | sudo tee -a /home/git/.ssh/authorized_keys
允许git用户通过SSH访问系统
Allow the git user to access the system via SSH
echo "AllowUsers git" | sudo tee -a /etc/ssh/sshd_config
sudo service ssh restart
创建存储位置
Create a location to store repositories
sudo mkdir -p /home/repo
sudo chown -R git:www-data /home/repo
创建一个HelloWorld仓库
Create a HelloWorld Repository
#Create the directory (always end with .git)
sudo mkdir /home/repo/helloworld.git
cd /home/repo/helloworld.git
#Initialize a bare repository
sudo git --bare init
#Some meta-data
echo "Hello World Repository. Testing system configuration" | sudo tee /home/repo/helloworld.git/description
echo "[gitweb]" | sudo tee -a /home/repo/helloworld.git/config
echo -e "\towner = \\"Rami Al-Ghanmi\\"" | sudo tee -a /home/repo/helloworld.git/config
#Fix ownership of repository
sudo chown -R git:www-data /home/repo/helloworld.git
克隆存储库,尽管为空,并添加了一些代码。
忽略关于克隆空存储库的警告。
Clone the repository, though empty, and add some code.
Ignore the warning about cloning an empty repository.
git clone git@$(hostname):/home/repo/helloworld.git
cd helloworld
wget https://raw.github.com/gist/3205222/HelloWorld.cpp
git add HelloWorld.cpp
git commit -m "Initial commit with HelloWorld in C++"
git push origin master
这篇关于git-shell - 新的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!