作者:心醉逸轩_620 | 来源:互联网 | 2023-01-02 09:09
1.检查是否已经有SSHKey。$cd~.ssh2.生成一个新的SSH。$ssh-keygen-trsa-Cemail之后直接回车,不用填写东西。之后会让你输入密码(
1.检查是否已经有SSH Key。
$cd ~/.ssh
2.生成一个新的SSH。
$ssh-keygen -t rsa -C "email"
之后直接回车,不用填写东西。之后会让你输入密码(可以不输入密码,直接为空,这样更新代码不用每次输入 id_rsa 密码了)。然后就生成一个目录.ssh ,里面有两个文件:id_rsa , id_rsa.pub(id_rsa中保存的是私钥,id_rsa.pub中保存的是公钥)
3.添加ssh key到GitHub/GitLab
在GitHub/GitLab上找到关于SSH keys->add key把id_rsa.pub公钥的内容复制进去就可以了。
4.配置账户
$ git config --global user.name “your_username”
$ git config --global user.email “your_registered_github_Email”
5.最后一步测试是否成功:
ssh -T git@"你的gitlab服务器地址"
The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is 16:27:xx:xx:xx:xx:xx:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/xxxx_000/.ssh/id_rsa':
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
接下来就可以通过ssh来提交代码了。