git config --global user.name "xxxx"
git config --global user.email "xxxxxx@163.com" #使用注册GitHub的邮箱
生成对应邮箱的密码对
ssh-keygen -t rsa -b 4096 -C "xxxxxx@163.com"
把公钥id_rsa.pub拷贝到github中
Setting----->SSH and GPG keys----->SSH keys------>添加新的keys---->把刚拷贝的公钥复制进去
测试是否成功:ssh -T git@github.com
Hi 22hao! You've successfully authenticated, but GitHub does not provide shell access.
连接成功。

要是这种报错就去把known_hosts文件对应的那条记录删掉,注意不是全部清空,免得其他已经实现免密登录的被干掉了
使用ssh下载代码
先在服务器生成秘钥

再把公钥添加到gitlab中

选择下载ssh方式的代码,这样就可以免密下载了,也可以再后面定义下载下来的名字