git -shell-新存储库



我有一个带有专用git用户和存储库的服务器
我正在尝试使用git-shell方法来允许我的开发人员从事多个项目。

我即将将git用户的外壳更改为git-shell
如果我这样做,我将无法再与标准外壳联系(这就是想法)。

问题:那么我将如何创建新存储库?

我每次都可以与sudoer建立联系并创建回购,然后再聊天?

您可以使用git-shell-commands目录使用自定义命令扩展git-shell,然后可以使用SSH远程执行。

例如,使用此内容创建~git/git-shell-commands/newgit

#!/bin/sh
mkdir -p ~/$1
cd ~/$1
git init --bare

然后 chmod +x ~git/git-shell-commands/newgit允许执行。

要使用它,运行:

ssh git@server newgit newrepo.git

这足以创建一个新的Bare Git存储库,可以使用以下方式克隆:

git clone git@server:newrepo.git

我每次都可以与sudoer连接并创建仓库然后chown?

是的,您可以在Rami Al-Ghanmi(alghanmi)的文章" Git Local存储库设置指南"中看到一个示例:

存储库设置&Essentials

首先,我们创建GIT用户并为SSH公共密钥身份验证和无终端登录设置帐户。
这意味着,GIT帐户无法使用密码(仅通过PKA)登录,并且没有常规的外壳访问。相反,它将使用具有有限命令的特殊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生成的密钥添加到授权密钥列表中。您可以为您希望访问

的所有用户重复此步骤
cat ~/.ssh/id_rsa.pub | sudo tee -a /home/git/.ssh/authorized_keys

允许GIT用户通过SSH

访问系统
echo "AllowUsers git" | sudo tee -a /etc/ssh/sshd_config
sudo service ssh restart

创建一个存储存储库的位置

sudo mkdir -p /home/repo
sudo chown -R git:www-data /home/repo

创建一个helloworld存储库

#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

克隆存储库,虽然为空,并添加一些代码。
忽略克隆空存储库的警告。

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

已经看了http://planzero.org/blog/2012/10/10/24/hosting_an_admin-friendly_git_git_git_server_with_with_with_git_git_git-shell

您可以在GIT用户的主目录中创建一个git-shell-commands目录,然后从页面中复制示例工具中,以通过访客shell创建回购。

最新更新