1.Git 安装
命令:sudo apt install git
2.查看安装的git版本
命令:git --version
3.申请 git帐号
git官网:https://github.com/
4.生成public key
命令:ssh-keygen -t rsa -C"xxx@xxx"
xxx@xxx为你的GIT邮箱。
(1)选择保存文件,我选择的是sshkey.
(2)输入两次密码,便会生成ssh key,并保存在sshkey.pub中。
Generating public/private rsa key pair.
Enter file in which to save the key (/home/lgj/.ssh/id_rsa): sshkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in sshkey.
Your public key has been saved in sshkey.pub.
The key fingerprint is:
SHA256:Cuee16KJJvm1pGcP601sbiIFryY20MY69uG9Izwg6Ik lgj_wish@163.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| |
| . |
|.o .o. S |
|+.+ +oo |
|+++o o* +. |
|E+B+BB+@+ . |
|.o.X*B@*+. |
+----[SHA256]-----+
5.查看public key
在保存目录打开sshkey.pub文件
命令:cat sshkey.pub
6.官网登陆帐号
(1)选择 帐号-设置
(2)选择左侧SSH and GPG Keys
(3)新建ssh key,Title随便写,复制sshkey.pub中的内容到key中。
7.测试ssh key 连接是否成功
使用命令“ssh -T git@github.com”,如果出现You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
如果出现:Permission denied (publickey).
输入命令:ssh -T -v git@github.com
可以看到一直在寻找 这四个文件。未找到就不再寻找。
这是因为上面我们设置的key文件为sshkey sshkey.pub.
将sshkey sshkey.pub.复制到.ssh中
命令:cp sshkey ./.ssh/id_rsa
cp sshkey.pub ./.ssh/id_rsa.pub
再一次进行测试:cp sshkey.pub ./.ssh/id_rsa.pub
成功显示:Hi lgjwish! You've successfully authenticated, but GitHub does not provide shell access.
如果用户创建多个KEY,将会有其他的问题,可参考其他网友的解决方案。