前言
本文是记录在ubuntu 14.04上创建git中心仓库的过程。
安装git
sudo apt-get install git
创建git用户
我们可以看见通用的git clone地址基本都是以git开头,如:
//@符号前的git其实就是git用户
[email protected]:tuzhao/rsftp.git
创建git用户的命令:
sudo adduser git
查看git用户是否成功创建:
1. cat /etc/passwd
//是否有类似下面这一行
git❌1002:1003::/home/git:/usr/bin/git-shell
2. cd /home
//是否有下面git这个文件夹
drwxr-xr-x 4 git git 4096 7月 15 13:15 git
初始化git中心仓库
//创建一个空的中心git仓库
[email protected]:/data/test$ sudo git init --bare test.git
Initialized empty Git repository in /data/test/test.git/
[email protected]:/data/test$ ls
total 12
drwxr-xr-x 3 root root 4096 7月 15 17:52 .
drwxr-xr-x 8 root root 4096 7月 15 17:52 ..
drwxr-xr-x 7 root root 4096 7月 15 17:52 test.git
[email protected]:/data/test$ pwd
/data/test
//将空的中心仓库改为git用户所属
[email protected]:/data/test$ sudo chown -R git:git test.git/
[email protected]:/data/test$ ls
total 12
drwxr-xr-x 3 root root 4096 7月 15 17:52 .
drwxr-xr-x 8 root root 4096 7月 15 17:52 ..
drwxr-xr-x 7 git git 4096 7月 15 17:52 test.git
禁止git用户shell登陆
处于安全考虑,我们都禁止git用户ssh方式登陆。
修改/etc/passwd文件,将git用户:
git❌1002:1003::/home/git:/bin/bash
修改为:
git❌1002:1003::/home/git:/usr/bin/git-shell
添加公钥
只有在公钥列表里的client端才能访问某一个git中心仓库。
将某一个公钥添加到 authorized_keys 这个文件中,一个公钥独占一行。
[email protected]:/home/git/.ssh$ pwd
/home/git/.ssh
[email protected]:/home/git/.ssh$ ls
total 12
drwxr-xr-x 2 git git 4096 7月 15 13:13 .
drwxr-xr-x 4 git git 4096 7月 15 13:15 ..
-rw-r--r-- 1 git git 398 7月 15 13:13 authorized_keys
clone中心仓库
以我这篇文章的路径为例,clone这个git仓库的地址为:
git clone [email protected]:/data/test/test.git
问题
在使用的过程中遇到了”Agent admitted failure to sign using the key.“这个问题。
解决办法是:
1.公钥添加是否正确;
2.在终端中输入ssh-add命令(是把专用密钥添加到ssh-agent的高速缓存中)。
本文由 tuzhao 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2018/07/15 13:09