Git安装和sshkey配置

系统环境 java

# linux CentOS Linux 7
root@localhost bin]#  uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

安装gitlinux

[root@localhost ~]# yum install git

git命令目录git

使用yum安装的在/usr/bin/gitgithub

[root@localhost bin]# pwd
/usr/bin
[root@localhost bin]# ./git version
git version 1.8.3.1

查看git版本dom

[root@localhost ~]# git version
git version 1.8.3.1

生成sshKeyssh

1) 查看sshkey是否存在gitlab

[root@localhost ~]# ls -al ~/.ssh
ls: 没法访问/root/.ssh: 没有那个文件或目录

2)不存在建立key测试

[root@localhost ~]# ssh-keygen -t rsa

连续按三次回车,即在本地生成了公钥和私钥,不设置密码,生成的公钥私钥在~/.ssh目录下,id_rsa是私钥,d_rsa.pub是公钥spa

3)查看key文件code

[root@localhost ~]# cd /root/.ssh
[root@localhost .ssh]# ls
id_rsa  id_rsa.pub

4)检查文件

[root@localhost .ssh]# ls -al ~/.ssh
总用量 12
drwx------.  2 root root   36 8月   4 09:51 .
dr-xr-x---. 19 root root 4096 8月   4 09:51 ..
-rw-------.  1 root root 1679 8月   4 09:51 id_rsa
-rw-r--r--.  1 root root  408 8月   4 09:51 id_rsa.pub

5)查看sshkey

[root@localhost .ssh]# cat id_rsa.pub
ssh-rsa CCAAB3NzaC1yc2EAAAADAQABAAABAQC1yxxxxslr1gdD8fZv3u6DbSc4ypYJ4zXsdGZyrDFrk6cvKHlKovGyid0D7udYFqSPYUBZnogxVbbKTuYnnhon4MylLPZV3jgNJzAsTVHdi0JbHBLDtg63aP443VM1YijkltNJHbqwMVfCH62w9Qb3GpBaxEm+m/e8ElxnRLLZ1xuXwY/RoAxtXyVEaSsRMBB/hVs7di5jy8WI36tpqJvcH4mw4X+ZXtQoFkt0fHxRIooQAifNyXKhGUTDxxvY2PpAKdmkYjM5WBoPve4QWua5+SlFX/FNETJSoCIMu/UIEfrMcJIR7Tukavcxx2Abm1YSl4J25psnaFxxaKSP3m1T root@localhost.localdomain

6)配置sshkey

在github或者gitlab中配置sshkey

7) 克隆仓库测试

[root@localhost mygit]# git clone git@10.1.100.140:chy2z/firstProject.git
[root@localhost firstProject]# git add .
[root@localhost firstProject]# git commit -m delete
[root@localhost firstProject]# git push origin master