前提:已安装git。
1、输入以下命令生成ssh key,一路回车即可。(xxxx@xxx.com为你注册GitHub的邮箱)(注意,Gitee只需这一步,然后复制密码就好)
GitHub:ssh-keygen -t rsa -C "xxxx@xxx.com"
Gitee:ssh-keygen -t ed25519 -C "xxxx@xxx.com"
$ ssh-keygen -t rsa -C "xxxx@xxx.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): 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:/ydX+AEdhH+HOukbM2knJNHjaa+vPhctxE70hDJv4ys "xxxx@xxx.com" The key's randomart image is: +---[RSA 3072]----+ | oo | | .o.o..| | . o*o+.| | o +Oo+| | S . =O.+o| | . ++o*.o| | ..B.o*.| | oEB= .| | .*@. | +----[SHA256]-----+
2、输入命令:eval "ssh-agent -s"
$ eval "ssh-agent -s" SSH_AUTH_SOCK=/tmp/ssh-pdrfl8Q4DvbK/agent.585; export SSH_AUTH_SOCK; SSH_AGENT_PID=586; export SSH_AGENT_PID; echo Agent pid 586;
3、继续输入命令:ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_rsa Identity added: /c/Users/Administrator/.ssh/id_rsa (xxxx@xxx.com)
如果报错(Could not open a connection to your authentication agent.),则需要先执行命令:ssh-agent bash,再执行上述命令
4、复制生成的key到GitHub
查看key:cat ~/.ssh/id_rsa.pub(Gitee:$ cat .ssh/id_ed25519.pub)
$ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCbLVIplXKxgdi2fi2ZhPW6o5dtF/mSeE3CmlFxmfUDoDgPaQDqebEiOaBNBN1GYvcpQxLXTkRuA9g7nf8DnH3qKfUq98QftsxbAcwvH1Xr0EcJFakMx7d0pGFH1RQ/kVr1iU3kKU4wuKhQn73Momje18BormKovP5InObSWNu7TAtkhmgF43W31NJjqS+mJ9v62Y7r65uetUgRwv9+MGJP3CO62TTLjdIom8VpK5uch7EGm3x6FYt8VT3urZS/ji/ixlvKaRJ7X1MJrCbQQ+8EfHejpKhQxZ0HU3p8CIjdbL1d9j1wIc8kz11zrEaoNSPdwK9J8pnl2o+TjoNQIUvNd0JHDsosCZARB0tzmuS0WnA3VvoldcIsMBfGC52bKW/zWuKkSUS0j+BTDvyk3aaS//ITmCnwffQeBo8C3A59KY00bEGDAWjhWhxJvQAhw3Qum7bZTIrC/glhwSxOcFSSEh0gu9hLLLQ2iq5CiNfbNv8/JpTPIDp/G+irUQ7URrE= "xxxx@xxx.com"
GitHub位置如下:
5、检查是否成功:
ssh -T "git@github.com" (Gitee:ssh -T git@gitee.com)
GitHub的连不上,Gitee倒是连上了
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.63.215)' can't be established.
ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
Hi mikasama! You've successfully authenticated, but GITEE.COM does not provide shell access.