打开终端输入如下指令
$ ssh-keygen -t ed25519 -C "工作邮箱,比如:[email protected]" > Generating public/private ed25519 key pair.
当系统提示您“输入要保存密钥的文件”时,按Enter键。将接受默认文件位置。如下:
> Enter a file in which to save the key (/Users/you/.ssh/id_ed25519): [Press enter]
在提示符下,输入安全密码,即可生成一个新的ssh密钥
注意: 如果生成ssh秘钥的时候输入了密码,则每次clone/push代码时都需要输入密码才行
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
复制ssk
$ pbcopy < ~/.ssh/id_ed25519.pub
git上添加ssh后,验证ssh的连通性
$ ssh -vT coding.test.com # Attempts to ssh to Coding
可能会常出现以下提示信息:
> debug1: Authentication succeeded (publickey). > Authenticated to coding.test.com ([172.20.39.5]:22). > debug1: channel 0: new [client-session] > debug1: Entering interactive session. > debug1: pledge: network > debug1: Sending environment. > debug1: Sending env LANG = zh_CN.UTF-8 > shell request failed on channel 0
表示使用ssh的方式,连通性已经验证通过:Authenticated to coding.test.com ([172.20.39.5]:22).