git-shell - 新的存储库

问题描述 投票:7回答:3

我有一个服务器与专用git用户和存储库 我正在尝试使用git-shell method让我的开发人员在几个项目上工作。

我即将把我的git用户的shell更改为git-shell 如果我这样做,我将无法再与标准shell连接(这就是主意)。

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

我是否每次都会与sudoer建立联系并创建回购然后将其展开?

git repository git-shell
3个回答
6
投票

我是否每次都会与sudoer建立联系并创建回购然后将其展开?

是的,你可以在Git Local Repository Setup Guide的文章“Rami Al-Ghanmi (alghanmi)”中看到一个例子:

存储库设置和要点

首先,我们创建了git用户并为SSH公钥认证设置了帐户,没有终端登录。 这意味着,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 generated key添加到授权密钥列表中。您可以为希望授予访问权限的所有用户重复此步骤

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

15
投票

您可以使用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

这足以创建一个新的裸git存储库,它可以使用以下方法克隆:

git clone git@server:newrepo.git

0
投票

看看http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell

您可以在git用户的主目录中创建一个git-shell-commands目录,然后从页面中复制示例工具以允许通过guest-shell创建repo。

© www.soinside.com 2019 - 2024. All rights reserved.