使用root登录服务器
useradd gituser # gituser---> 用户名字
passwd gituser
vi /etc/ssh/sshd_config
RSAAuthentication yes # 启用RSA 非对称加密算法
PubkeyAuthentication yes # 公钥认证
PasswordAuthentication yes #允许密码认证
systemctl restart sshd.service
su - gituser # 因为你是root 无需密码
查看当前位置是/home/gituser,不是,切换到/home/gituser
创建一个git仓库
git init --bare myproject.git # myproject.git --> 仓库名字
mkdir .ssh
chmod 700 .ssh
cd .ssh
touch authorized_keys
chmod 600 authorized_keys
vi authorized_keys # 里面写入本机的公钥
i # 写入
Esc :x # 保存并退出
Host myserver_git # 本机要连接服务器的名字
HostName 127.0.0.1 # 举例 服务器的IP
User gituser # 服务器上的用户
Port 22
PreferredAuthentications publickey
IdentityFile C:\Users\Jack-Roc\.ssh\jack_rsa # 指定本机的私钥地址
git clone gituser@myserver_git:~/myproject.git # myproject.git 服务器git仓库的名字·
或
git clone gituser@myserver_git:/home/gituser/meproject.git # 写给i他仓库绝对地址
touch readme.txt # 创建readme.txt 文件
git add readme.txt # 添加到暂存区中
git commit -m "添加readme文件" # 提交到本地版本库里
git push origin # 推送到远程仓库
git pull origin # 拉取文件
他人和自己想用一个git仓库的话将他人的公钥传给你
写入自己服务器的.ssh/authorized_keys 中 (空一行直接写他人的公钥)
原文:https://www.cnblogs.com/xinzaiyuan/p/12070728.html