歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> 手把手教你在ubuntu中搭建git服務器

手把手教你在ubuntu中搭建git服務器

日期:2017/3/2 16:33:22   编辑:Linux服務器

服務器端:

  a@ubuntu:~$ sudo apt-get install git-core

  a@ubuntu:~$ sudo apt-get install openssh-server

  a@ubuntu:~$ sudo apt-get install openssh-client

  新加用戶git,該用戶將作為所有代碼倉庫和用戶權限的管理者:

  a@ubuntu:~$ sudo useradd -m git

  為git設置密碼:

  a@ubuntu:~$ sudo passwd git

  安裝一下python的setup tool, 這個也是為了gitosis做准備:

  apt-get install python-setuptools

  git clone git://eagain.net/gitosis.git

  cd gitosis

  python setup.py install

  客戶端:

  shh git@服務器

  登錄到服務器後

  mkdir example.git

  cd example.git

  git --bare init

  cd

  ssh localhost

  exit

  客戶端:

  生成ssh key並傳到git server上

  ssh-keygen -t rsa

  scp ~/.ssh/id_rsa.pub git@服務器:~/.ssh/

  ssh git@服務器

  cat ~/.ssh/id_rsa.pub >> authorized_keys

  chmod 755 /home/git

  chmod 700 /home/git/.ssh

  chmod 644 /home/git/.ssh/authorized_keys

  chmod 755 /www/git/repositories/gitosis-admin.git/\

  hooks/post-update

  exit

  mkdir example

  cd example

  git init

  touch README

  git add README

  git commit -m 'first commit'

  git remote add origin git@服務器:example.git

  git push origin master

  我比較腦子轉不過彎,網上好幾個說建服務器,說得太詳細了,不過我覺得有些還是按默認的吧,現階段我的linux不是很強,就笨點吧, 生成ssh key並傳到git server上 一定要在客戶機上,我一段時間一直就再這轉不過完

Copyright © Linux教程網 All Rights Reserved