ubuntu server 端:
apt install git
apt install openssh-server
在服务器上部署git仓库:
mkdir repos
sudo addgroup git-rw
sudo chgrp -R git-rw repos
ls -l
sudo useradd -M -g git-rw gitteacher
sudo passwd gitteacher
sudo useradd -M -g git-rw gitstudent
sudo passwd gitstudent
客户端:
mkdir git_teacher
cd git_teacher/
git init
touch README.md
vim README.md
git add -A
git commit -m"initial commit"
cd .. && git clone --bare git_teacher git_teacher.git #退回上一级目录,克隆一个仓库出来
scp -r git_teacher.git gitteacher@192.168.1.109:/home/ml/repos #复制裸仓库到服务端
客户端2:
git clone gitstudent@192.168.1.109:/home/ml/repos/git_teacher.git
服务端:
sudo chmod -R g+w repos/git_teacher.git
ls -l repos/git_teacher.git/
git push origin master # 将本地主分支推到远程主分支
git pull # 抓取远程仓库所有分支更新并合并到本地
使用 SSH 公钥管理 Git 仓库授权:
服务端:
sudo adduser git
su git
cd /home/git/
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
客户端:
cd ~/.ssh/
ls
mv id_rsa id_rsa.bak #备份私钥
mv id_rsa.pub id_rsa.pub.bak #备份公钥
ssh-keygen #重新生成私钥公钥
cat id_rsa.pub | ssh git@192.168.1.109 'cat - >> ~/.ssh/authorized_keys' #导入公钥到服务器
服务端:
禁止git用户登录shell,只允许git登录git-shell操作
which git-shell
sudo vim /etc/shells
sudo chsh git
/usr/bin/git-shell
exit
使用Git-GUI访问服务器仓库:
本文属于转载:
http://www.jikexueyuan.com/course/1700_3.html?ss=1
时间: 2024-11-05 14:52:33