Ubuntu 安裝 git 倉庫

參考鏈接1
參考鏈接2

  1. 本地電腦創建 ssh 密鑰
ssh-keygen -t rsa //這時會要求你輸入保存密鑰的路徑,這時只需要點擊回車保存在默認路徑
cat ~/.ssh/id_rsa.pub //查看公鑰,之後要粘貼到服務器的 authorized_keys 文件中
  1. 創建 git 用戶
adduser git
  1. 創建證書登錄
su - git // 中間有空格, -  不能省略,不然後面可能會出現沒有權限創建文件夾ssh
mkdir .ssh
chmod 700 .ssh
touch ~/.ssh/authorized_keys 
chmod 644 ~/.ssh/authorized_keys 
vim ~/.ssh/authorized_keys //把公鑰複製到~/.ssh/authorized_keys
  1. 初始化git倉庫
cd /home/git/
mkdir gitrepo
cd gitrepo
git init
chmod -R 777 gitrepo //初始化完後更改讀寫權限可能還要修改擁有者等權限
  1. 禁用shell登錄
which git-shell 
//得到路徑 /usr/bin/git-shell
vim /etc/passwd
	git:x:1001:1001:,,,:/home/git:/bin/bash
	改爲
	git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
  1. 本地電腦克隆
git clone [email protected]:/home/git/gitrepo
  1. 讓倉庫接受代碼提交
vim .git/config
	[receive]
	denyCurrentBranch = ignore
  1. 或者本地不克隆,添加遠程
git remote add origin user@ip:/home/git/gitrepo
  1. 設置服務器端更新鉤子 post-update
cd .git/hooks
vim post-receive
//將如下內容複製到文件中
	#!/bin/sh
	unset GIT_DIR
	cd ..
	git checkout -f
//保存後修改讀寫權限
chmod 777 post-receive
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章