win+r 打开cmd窗口,路径是当前用户目录
输入生成sshkey命令:
ssh-keygen -t rsa -C 'xxx@xxx.com' -f ./.ssh/xx_id_rsa
代码参数含义:
-t 指定密钥类型,默认是 rsa ,可以省略。
-C 设置注释文字,比如邮箱。
-f 指定密钥文件存储文件名。
gitee上的教程是
ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/github_id_rsa
~是linux的用户目录,windows可以使用.来代替。
指定生成的key文件名,一是使用上面的-f参数,
二是不加参数,直接回车会提示输入文件名
C:\Users\xx>ssh-keygen -t rsa -C 'xxx@xxx.com'
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\xx/.ssh/id_rsa): ./.ssh/xx_id_rsa
然后在.ssh目录下创建文件名为config的文件(无后缀),编写配置:
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/xx_id_rsa
Host :对应使用git clone git@gitee.com:xx.git @后面的gitee.com,可以是HostName的自定义别名
HostName :真实的域名
PreferredAuthentications
IdentityFile :id_rsa文件路径
最后执行测试
ssh -T git@gitee.com
突然报错:git@gitee.com: Permission denied (publickey).
搜了下,是没有把sshkey添加到gitee,把生成的rsa.pub文件里的内容复制粘贴到gitee添加ssh公钥页面即可。
主要参考gitee的教程:
https://gitee.com/help/articles/4229#article-header0
ssh-keygen命令相关参考:
https://www.cnblogs.com/yanglang/p/9563496.html
ssh config相关资料
https://www.ssh.com/ssh/config/#format-of-ssh-client-config-file-ssh_config
ssh config参考博客
https://www.cnblogs.com/popfisher/p/5731232.html