linux上安装git远程仓库

1 安装

输入命令

git --version

若出现 -bash:git:command not found则需要安装git

输入命令

yum –y install git

安装完后,查看Git版本,如下图所示

2 设置用户

创建git用户,输入命令

useradd git

创建了名为git的用户

为git用户设置密码,输入命令

passwd git

输入两次密码,设置密码成功

3 创建仓库

在git的用户目录下创建仓库:

#进入git用户目录
cd /home/git

#创建仓库learngit
git init --bare learngit.git

#为git用户赋权限
chown -R git:git learngit.git

4 打开RSA认证

编辑 sshd_config

sudo vi /etc/ssh/ssh_config

打开一下配置的注释

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

重启sshd服务

/etc/rc.d/init.d/sshd restart

重启完成之后,git服务就安装完成了

5 客户端配置

打开git bash创建git使用者

git config --global user.name "suboya"
git config --global user.email "[email protected]"

创建与服务器通讯密钥,为邮箱创建

ssh-keygen -t rsa -C "[email protected]"

一路enter下午,系统已经为我们创建了一个公钥(id_rsa)和私钥(id_rsa.pub)。

将公钥添加进远程服务器中

 ssh [email protected] 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

如果/home/git/目录下没有.ssh目录,需要先创建目录

6 克隆远程仓库

创建本地git仓库文件夹

#进入需要创建的目录
cd /Users/suboya/src/

#创建本地git仓库文件夹
mkdir learngit

克隆远程仓库

git clone [email protected]:/home/git/learngit.git
发布了32 篇原创文章 · 获赞 38 · 访问量 5478

猜你喜欢

转载自blog.csdn.net/u010482601/article/details/103301535