-
打开Git bash检查本地已有SSH
$ ls -al ~/.ssh
命令窗口会返回已有.ssh文件夹下文件,如:
>>total 22
>>drwxr-xr-x 1 admin 197121 0 May 1 23:19 ./
>>drwxr-xr-x 1 admin 197121 0 May 1 23:00 ../
>>-rw-r--r-- 1 admin 197121 232 May 1 23:00 config
>>-rw-r--r-- 1 admin 197121 411 May 1 22:23 id_ed25519_gitee
>>-rw-r--r-- 1 admin 197121 102 May 1 22:23 id_ed25519_gitee.pub
>>-rw-r--r-- 1 admin 197121 411 May 1 22:02 id_ed25519_github
>>-rw-r--r-- 1 admin 197121 98 May 1 22:02 id_ed25519_github.pub
>>-rw-r--r-- 1 admin 197121 91 May 1 23:19 known_hosts
-
复制公钥
很多时候刚创建完ssh直接在命令行窗口复制返回的公钥,很容易会出现格式错误导致在远端添加SSH时失败,所以可以运行以下命令将SSH公钥复制到剪贴板上
$ clip < ~/.ssh/id_ed25519_github.pub
以上两步也可以直接在文件目录里打开.ssh文件夹找到目标文件记事本打开复制。
-
在远端粘贴SSH公钥
-
本地运行 (验证连接)
$ ssh -T git@github.com
可能会出现
>>The authenticity of host 'github.com (212.64.62.183)' 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继续
命令行窗口返回:
>>Hi Mark! You've successfully authenticated,
>>but GITHUB.COM does not provide shell access.
说明连接成功。