1、首先需要安装Git,可以使用yum源在线安装:
yum install -y git
2、创建一个git用户,用来运行git服务
adduser git
passwd git
【输入密码,后面git clone 下来就是这个密码】
3、初始化git仓库:这里我们选择/data/git/learngit.git来作为我们的git仓库
mkdir /data/git -p
cd /data/git
git init --bare java.git #初始化仓库123
执行以上命令,会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾。然后,把owner改为git
chown git:git java.git -R
4、验证
git clone git@47.101.211.80:/data/git/learngit.git
输入密码
warning: You appear to have cloned an empty repository.
然后本地出现learngit 文件夹
5、本地cd learngit 增加一个poem.txt
git add .
git commit -m 'the first'
$ git remote add origin git@47.101.211.80:/data/git/learngit.git
fatal: remote origin already exists.
git remote add master git@47.101.211.80:/data/git/learngit.git
git push -u origin master
输入密码,然后OK
安装结果
输入命令: git --version ,查看安装的Git版本,验证是否安装成功;
5、查看安装信息
Git默认安装在/usr/libexec/git-core目录下,可输入指令,查看安装信息:
/usr/libexec/git-core
-------------------------------------------------------------------------------------------
git clone 总是报错
git clone git@47.101.211.80:/data/git/learngit.git
Cloning into 'learngit'...
git@47.101.211.81's password:
Permission denied, please try again.
git@47.101.211.81's password:
Permission denied, please try again.
git@47.101.211.81's password:
git@47.101.211.81: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
经过排查发现是文件权限问题。
2019年6月22日
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
解决:
chown -R git:git /home/git
chmod 700 /home/git
mkdir /home/git/.ssh
chmod 700 /home/git/.ssh
touch /home/git/.ssh/authorized_keys
chmod 644 /home/git/.ssh/authorized_keys
vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile /home/git/.ssh/authorized_keys
(2)重启sshd服务
systemctl restart sshd.service
systemctl status sshd.service #查看ssh服务的状态
参考文章:
https://blog.csdn.net/guyan0319/article/details/79111600
https://blog.csdn.net/xinxin19881112/article/details/73322085