一、配置用户信息和ssh key
配置user.email
以及user.name
:
1 2 |
git config --global user.name "maqian" git config --global user.email "maqian@dyxmq.cn" |
生成公私密钥:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@localhost git-2.15.1]# ssh-keygen -t rsa -C "maqian@dyxmq.cn" Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): # 文件的生成目录 Created directory "/root/.ssh". 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: c2:4f:68:c6:14:8a:20:cf:78:72:a4:23:df:f7:cb:5c maqian@dyxmq.cn The key"s randomart image is: +--[ RSA 2048]----+ |o . . | |.B . . . | |* * . . | |.* . + . | | . . O S | | + = | | o E | | o o | | + | +-----------------+ |
二、上传密钥到github
上面生成了两个密钥文件,默认位于~/.ssh/
目录下:
1 2 3 |
[root@localhost git-2.15.1]# ll ~/.ssh/* -rw-------. 1 root root 1675 Dec 18 04:01 /root/.ssh/id_rsa -rw-r--r--. 1 root root 397 Dec 18 04:01 /root/.ssh/id_rsa.pub |
其中id_rsa
是私钥,id_rsa.pub
是公钥,我们要把公钥的内容上传到github
。查看公钥并复制:
1 2 |
[root@localhost git-2.15.1]# cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArPMU4FnFQii0SYmUg2USSV6FId8eILptRew7iQqDyEtZIe6cKB6Z8Rkqk3ZKd8VclbAKKRJZCnwR6wHHXmYtm/i19DmGOHDuxuY+MkWtWB3bFsQKlQe4OaAoCvLqlRS7S+3Jppw5Uu5zZf85AABmutbGZq0/Fk*********************************************************************************************lbjJZ+uCchBf3VttiWD0gnyTjubYiBc4i5StOefGrfogTYz22dNZodguwcBb83v09zqp5l46WeIWG33sse+Me4R5B5Q== maqian@dyxmq.cn |
打开github,右上角Settings
进入设置界面,在SSH and GPG keys
栏新建一个ssh key
:
填入复制的密钥对,Title
可以随便写:
测试是否验证成功:
1 2 3 4 5 |
[root@localhost git-2.15.1]# ssh -T git@github.com The authenticity of host "github.com (192.30.255.113)" can"t be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Hi madawang! You"ve successfully authenticated, but GitHub does not provide shell access. |
出现以上信息就表示已经可以成功连上github了,然后就能对版本库进行操作了。
评论