1.设置用户名和邮箱
$ git config --global user.name "gsx-gh" $ git config --global user.email "gsx@126.com"
2.生成密钥
$ ssh-keygen -t rsa -C "gsx@126.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): Created directory '/c/Users/Administrator/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa. Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub. The key fingerprint is: SHA256:XwstvBad8mew3XT+IRSPV9+EZEL6WNEje+dW/qzAGFo gsx@126.com The key's randomart image is: +---[RSA 2048]----+ | .+.o | | ..=o. | | . .+..o| | . *..=.*| | S E B+ **| | + %.=.+=| | . = *.+++| | . +. =| | ...| +----[SHA256]-----+
3.复制/c/Users/Administrator/.ssh/id_rsa.pub中生成的内容,登陆github账号添加ssh-key
title自定义
将公钥添加到key中,点击ADD保存
4.测试
$ ssh -T git@github.com The authenticity of host 'github.com (192.30.253.112)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts. Hi gsx! You've successfully authenticated, but GitHub does not provide shell access.
出现以上信息,则设置成功,可以使用ssh访问提交代码。
ps:以上命令在gitbash软件命令行执行。安装git