ssh-keygen -t ed25519 -C "your_email@example.com" or ssh-keygen -t rsa -b 4096 -C "your_email@example.com" #####输出 Generating public/private ed25519 key pair. Enter file inwhich to save the key (/c/Users/libai/.ssh/id_ed25519): # 文件存储位置 Enter passphrase (empty for no passphrase): # 输入密钥 密码 可留空 Enter same passphrase again: # 确认密码 Your identification has been saved in /c/Users/libai/.ssh/id_ed25519 # 储存位置 私钥 Your public key has been saved in /c/Users/libai/.ssh/id_ed25519.pub # 存储位置 公钥 The key fingerprint is: SHA256:JiEaUc9F3/yd6WsU2nAnl5PHTcIXyS5K/4RnIV+Cx2Y dufukai@zhengzihui.com The key's randomart image is: +--[ED25519 256]--+ | ... .o ...o| | . o . . o ooo| | . . + . oo.=+| | o . . ..=EXX| | . . S . o+@*O| | o . +.B | | *. | | o.| | .. | +----[SHA256]-----+
复制公钥到 github、gitlab
id_ed25519 为私钥
id_ed25519.pub 为公钥
打开公钥id_ed25519.pub,复制内容 到github或者 gitlab中。
测试ssh连接
1 2 3 4 5 6 7 8 9 10 11 12
ssh -T git@github.com or ssh -T git@192.168.5.130 # 自建gitlab地址
您可能会看到类似如下的警告:
> The authenticity of host 'github.com (IP ADDRESS)' can't be established. > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. > Are you sure you want to continue connecting (yes/no)? 输入 yes 就可以了