Github 添加 ssh key 报错:Key is invalid. You must supply a key in OpenSSH public key format

密钥格式不正确!!

复制 .pub 文件里的密钥 (利用 cat 命令查看)



如何生成密钥?

ssh-keygen -t rsa -C "xxx"   # xxx为GitHub上注册的邮箱
  • Enter file in which to save the key: 选择生成的 key 存放的位置(如果直接回车则选择它括号中默认的路径)
  • Enter passphrase / Enter same passphrase again: 输入密码(可不填,直接回车就行)

然后你就能看见一个框起来还挺好看的 RSA,说明密钥已经生成。直接去刚刚选择的路径中查看复制密钥就行~

密钥已经在 GitHub 添加成功了,git clone 的时候报错:

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.  Please make sure you have the correct access rights and the repository exists.

原因:你本机的 git 仓库并没有和这个 SSH key 关联上。
解决方法

ssh-add 你的id-rsa文件地址

⚠️注意这里 ssh-add 后面填的是私钥地址,如 mac 电脑是 /Users/用户名/.ssh/id_rsa

add 之后可以用 ssh [email protected] 验证是不是添加成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章