centos 6.5 安装git

安装GIT

yun install git
yun install openssh-server openssh-client

注解:安装openssh-serveropenssh-client是由于git需要通过ssh协议来在服务器与客户端之间传输文件

添加用户名和密码

[html]  view plain  copy
 print ?
  1. sudo adduser git  

生成公钥

[html]  view plain  copy
 print ?
  1. sudo ssh-keygen -t rsa -C "[email protected]"  
注意 : 这里生成的文件是隐藏文件  
把生成的公钥复制到/root/.ssh/id_rsa.pub公钥复制到 /home/git/.ssh/authorized_keys 如果.ssh不存在创建文件夹 如果不存在创建文件  authorized_keys

 开启权限:

[html]  view plain  copy
 print ?
  1. ubuntu@VM-49-49-ubuntu:~$ sudo chmod 777 /home  
  2. ubuntu@VM-49-49-ubuntu:~$ sudo chmod 777 /home/git/  
  3. ubuntu@VM-49-49-ubuntu:~$ sudo chmod 777 /home/git/.ssh/  
  4. ubuntu@VM-49-49-ubuntu:~$ sudo chmod 777 /home/git/.ssh/authorized_keys  
  5.    

  // sudo vim /root/.ssh/id_rsa.pub

先选定一个目录作为Git仓库,假定是/srv/sample.git,在/srv目录下输入命令:

sudo git init --bare sample.git

Git就会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾。然后,把owner改为git

$ sudo chown -R git:git sample.git

第五步,禁用shell登录:

出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:

git:x:500:500:,,,:/home/git:/bin/bash

最终改为:

git:x:500:500:git version control:/home/git:/usr/bin/git-shell

这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。

第六步,克隆远程仓库:

现在,可以通过git clone命令克隆远程仓库了,在各自的电脑上运行:

$ git clone git@server:/srv/sample.git
Cloning into 'sample'...
warning:You appear to have cloned an empty repository.

剩下的推送就简单了。

这会你可以用root 用户访问了


同步代码操作

找到你的仓库 fwc.git/hooks

 创建文件

vim post-receive 

内容


给钩子文件

git --work-tree=/var/www/html/fwc checkout -f
#chown git:git post-receive
chown git:root post-receive
chmod +x post-receive



给钩子文件添加执行权限

$ cd /home/git/fwc.git/hooks/
$ chmod +x post-recevie //给钩子文件添加执行权限


添加多个用户

sudo adduser git
编辑sudo vim /etc/passwd

常碰到的错误   是因为多次  输入密码错误    导致
Too many authentication failures for root
解决
ssh配置文件路径 
MAC下 /etc/sshd_config
Linux下 /etc/ssh/sshd_config
修改后重启ssh服务即可
 
这个解决不了实质问题     

 系统默认有三种登录方式   
我们把登录方式切换成密码登录就可以
 
  
 
  
把sourcetree->工具-》验证 多余登录删掉就可以了

猜你喜欢

转载自blog.csdn.net/qiu1988yang/article/details/78405700
今日推荐