安装基础包
直接安装tig命令,因为git是tig依赖的,所以git会被一起安装上。
yum install tig -y
配置
执行ssh-keygen -t rsa,默认会在./root/.ssh/目录下生成id_rsa.pub公钥文件,该文件后面需要用来添加到github配置中。
[root@anonymous ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:fudmE8Vhi9Ln2kearzOaVEy90xCBGaONAx1QKAkRWhY root@anonymous
The key's randomart image is:
+---[RSA 2048]----+
| E= . .++..o+o. |
| + o . ..+o.o..|
|. . +..+.oo|
| ..o =+o|
| S . + o+|
| . . ..o|
| . . .+.+ |
| . o=.B .|
| o..oO.|
+----[SHA256]-----+
[root@anonymous ~]# cd .ssh/
[root@anonymous .ssh]# ls
id_rsa id_rsa.pub known_hosts
github上配置
登录自己的github账号,单击右上角的头像->settings->SSH and GpG keys->New SSH key
验证配置是否成功
通过执行ssh -T git@github.com 验证前面的配置是否成功,如果看到最后面的successfully authenticated字样,表示已经配置成功。
[root@anonymous ~]# ssh -T git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomT3dCARLviKw6E5SX8.
RSA key fingerprint is MD5:16:27:ac:5a:76:28:2d:36:63:1b:56:3d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi your_github_username! You've successfully authenticated, but GitHub does not provide shell access.
[root@anonymous ~]# ls
配置用户名和邮箱并拉取仓库测试
[root@anonymous ~]# git config --global user.name "myusername"
[root@anonymous ~]# git config --global user.email "test@gmail.com"
[root@anonymous ~]# git clone git@github.com:myusername/2021.git
Cloning into '2021'...
remote: Enumerating objects: 14, done.
remote: Total 14 (delta 0), reused 0 (delta 0), pack-reused 14
Receiving objects: 100% (14/14), 5.82 KiB | 0 bytes/s, done.
Resolving deltas: 100% (3/3), done.
You have mail in /var/spool/mail/root
[root@anonymous ~]#