git_linux搭建服務器

爲什麼本地搭建一個git服務器

  • 對於自己學習使用的代碼,在沒有網絡的情況下不能用github,gitlab,所以本地建立一個git服務器。

git服務器環境準備centos7

服務端創建git用戶

	id git # 查看是否存在git用戶,存在就不創建了。
	useradd git
	passwd git
	輸入密碼,我設置的是xxx@123
	

客戶端開啓公鑰認證認證,免密push/pull

  • 首先服務端需要開啓ssh服務
vim /etc/ssh/sshd_config
RSAAuthentication yes 
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
如果是centos7.4以上(含7.4),ssh1已經不支持了,只支持ssh2代協議。所以RSAAuthentication項是沒有的

  • 客戶端執行 執行ssh-keygen -t rsa 生成公鑰和私鑰
  • 複製客戶端公鑰到服務器端ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

服務端創建git倉庫

	mkdir -p /data/git/gittest.git
	
	# 初始化這個倉庫
	cd /data/git/gittest.git
	git init --bare .
	
	# 目錄所屬用戶設置
	chown -R git:git /data/git 
	

客戶端clone遠程倉庫

	mkdir localgit
	cd localgit
	git clone [email protected]:/data/git/gittest.git .
	# 提示輸入服務端git賬戶的密碼。
	#修改完就可以提交了
	
	touch abc.txt
	git add .
	git commit -m 'aaa'
	git push 
	
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章