centos下搭建git服务器

1.安装GIT

[root@localhost ~]# yum install -y git
2.创建git帐号

[root@localhost ~]# useradd git
[root@localhost ~]# passwd git
[root@localhost yjx2]# su git
3.创建git仓库 
[git@localhost ~]$ git init --bare learngit.git
注意:在git用户下创建learngit.git 文件归属git

如果没有执行chown更改文件归属

[root@localhost git]# chown git:git learngit.git
4.客户端创建生成密钥ssh key

[yjx@localhost ~]$git config --global user.name "jingsia"
[yjx@localhost ~]$git config --global user.email "xxx@xx.com"
[yjx@localhost ~]$ssh-keygen -t rsa -C "xxx@xx.com"
这里会生成 id_rsa 和 id_rsa.pub 一个是私有密钥 一个是公有密钥

[yjx@localhost ~]$ ls .ssh/id_rsa*
.ssh/id_rsa  .ssh/id_rsa.pub
5.git服务器打开RSA认证

打开文件

[root@localhost ~]# vim /etc/ssh/sshd_config
设置

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
6.git服务器添加客户端密钥

创建authorized_keys文件 并将客户端密钥输入到文件中 保存退出

[root@localhost ~]$ touch .ssh/authorized_keys

注意:authorized_keys归属root

[root@localhost ~]# ll /home/git/.ssh/
total 4
-rw-r--r--. 1 root root 398 Jan 14 17:07 authorized_keys

7.客户端使用

git clone git@192.190.71.99:/home/git/learngit.git


常见问题:

1.not a valid object name master

使用Git来管理代码,第一次远程分支上什么都没,也没有本地分支。想建新的分支也没用。提示:not a valid object name master,查了下资料需要先添加点东西。所以在本地git库中新增了一个文件,然后在git命令行中敲入git commit 

2.已经添加客户端key但是还是让输入密码

1)authorized_keys文件归属不对,归属root用户下,即:

[root@localhost ~]# mkdir /home/git/.ssh
[root@localhost .ssh]# vim authorized_keys
[root@localhost .ssh]# cat ../id_rsa.pub >> authorized_keys


参考:

1.http://www.cnblogs.com/lovychen/p/5900688.html

2.http://blog.csdn.net/hustpzb/article/details/8230454/

3.http://blog.csdn.net/wave_1102/article/details/47779401

4.http://blog.csdn.net/spring123tt/article/details/49867359

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值