Linux上安装和部署git
本机环境:
[git@rhel-server .ssh]$ cat /proc/version
Linux version 2.6.32-358.el6.x86_64
1.安装
yum install git
[git@rhel-server hello.git]$ yum list git
已加载插件:fastestmirror, product-id, subscription-manager
Determining fastest mirrors
已安装的软件包
git.x86_64 1.7.1-9.el6_9
2.初始化配置
git config --global user.name laoxu
git config --global user.email 123@example.com
3.创建git用户
sudo adduser git
su git
cd
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
4.打开RSA认证
4.1.修改配置文件
[git@rhel-server .ssh]$ sudo vim /etc/ssh/sshd_config
找到以下几行,把注释去掉
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
4.2.生成公钥【客户端】
$ ssh-keygen
一路回车默认即可。
ACER@luohanye MINGW64 ~/.ssh
$ ls
id_rsa id_rsa.pub known_hosts
4.3.上传到git服务器:
scp id_rsa.pub git@192.168.56.101:/home/git/keys/indexman.pub
将id_rsa.pub中内容复制到authorized_keys文件:【服务端】
[git@rhel-server .ssh]$ cat indexman.pub >>../.ssh/authorized_keys
4.4.本地clone git仓库
无需输入密码。
$ git clone git@192.168.56.101:/home/git/projects/hello.git
Cloning into 'hello'...
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 26 (delta 2), reused 0 (delta 0)
Receiving objects: 100% (26/26), 6.16 KiB | 0 bytes/s, done.
Resolving deltas: 100% (2/2), done.
5.客户机clone仓库【客户端】
[root@rhel-server ~]# ssh git@192.168.56.101
The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.
RSA key fingerprint is b6:9a:24:cf:e7:d5:dc:f5:bb:66:13:9a:fe:f4:15:11.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.101' (RSA) to the list of known hosts.
git@192.168.56.101's password:
6.配置git服务器,初始化裸仓库
[git@rhel-server projects]$ mkdir hello.git
[git@rhel-server projects]$ cd hello.git/
[git@rhel-server hello.git]$ git init --bare
7.将本地项目上传至git服务器【客户端】
切换到本地项目目录:例如 e:\ideaprojects\hello
git init
git add .
git commit -m 'init'
git remote add origin git@192.168.56.101:/home/git/projects/hello.git
git push origin master
git@192.168.56.101's password:
8.或是克隆已有的git仓库【客户端】
切换到指定目录:例如 d:\test
$ git clone git@192.168.56.101:/home/git/projects/hello.git