github远程克隆失败: 创建公钥

目录

解决方法

        第一步

        第二步

        第三步

        第四步

        第五步

        最后


使用 git clone ******SSH命令克隆远程仓库时,报

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ git clone git@github.com:chensaury/pds_serve_motor_simulink.git
Cloning into 'pds_serve_motor_simulink'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

判定是在本地(或服务器上)没有生成SSH公钥


解决方法
第一步

当你没有SSH公钥的时候,在Terminal中输入下面的命令:

ssh-keygen -t rsa -C "*******@**.com"

按回车键,会出现下面图示中的内容,根据提示输入y或按enter回车,最终会生成SSH公钥。(如果重新生成的话会覆盖之前的SSH公钥)

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ ssh-keygen -t rsa -C "13447297559@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/saury/.ssh/id_rsa):
/c/Users/saury/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/saury/.ssh/id_rsa
Your public key has been saved in /c/Users/saury/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:VvX1cV3fvEJiMK/4XaILFXloAXQMJrKTnVkTxVBnJWo 13447297559@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|   . ..XXB +o. .*|
|    = * oo@... oB|
|   + +   E.= .. =|
|    .   +.= o   .|
|       .So . o . |
|       .o o o .  |
|       . o .     |
|        . .      |
|         .       |
+----[SHA256]-----+

第二步

继续在Terminal中输入如下命令:

ssh -v git@github.com

如果提示输入就y

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ ssh -v git@github.com
OpenSSH_9.0p1, OpenSSL 1.1.1q  5 Jul 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [20.205.243.166] port 22.
debug1: Connection established.
debug1: identity file /c/Users/saury/.ssh/id_rsa type 0
debug1: identity file /c/Users/saury/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/saury/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/saury/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/saury/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/saury/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/saury/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/saury/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/saury/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/saury/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/saury/.ssh/id_xmss type -1
debug1: identity file /c/Users/saury/.ssh/id_xmss-cert type -1
debug1: identity file /c/Users/saury/.ssh/id_dsa type -1
debug1: identity file /c/Users/saury/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version babeld-9713928c
debug1: compat_banner: no match: babeld-9713928c
debug1: Authenticating to github.com:22 as 'git'
debug1: load_hostkeys: fopen /c/Users/saury/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
debug1: load_hostkeys: fopen /c/Users/saury/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'github.com' is known and matches the ED25519 host key.
debug1: Found key in /c/Users/saury/.ssh/known_hosts:2
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/saury/.ssh/id_rsa RSA SHA256:VvX1cV3fvEJiMK/4XaILFXloAXQMJrKTnVkTxVBnJWo
debug1: Will attempt key: /c/Users/saury/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/saury/.ssh/id_ecdsa_sk
debug1: Will attempt key: /c/Users/saury/.ssh/id_ed25519
debug1: Will attempt key: /c/Users/saury/.ssh/id_ed25519_sk
debug1: Will attempt key: /c/Users/saury/.ssh/id_xmss
debug1: Will attempt key: /c/Users/saury/.ssh/id_dsa
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/saury/.ssh/id_rsa RSA SHA256:VvX1cV3fvEJiMK/4XaILFXloAXQMJrKTnVkTxVBnJWo
debug1: Authentications that can continue: publickey
debug1: Trying private key: /c/Users/saury/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/saury/.ssh/id_ecdsa_sk
debug1: Trying private key: /c/Users/saury/.ssh/id_ed25519
debug1: Trying private key: /c/Users/saury/.ssh/id_ed25519_sk
debug1: Trying private key: /c/Users/saury/.ssh/id_xmss
debug1: Trying private key: /c/Users/saury/.ssh/id_dsa
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

出现如上最后两句即可


第三步

在Terminal中输入如下命令:

ssh-agent -s

Terminal中会显示与下图中类似的信息

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-er4vx6KikL7A/agent.1585; export SSH_AUTH_SOCK;
SSH_AGENT_PID=1586; export SSH_AGENT_PID;
echo Agent pid 1586;

第四步

在Terminal中输入如下命令:

ssh-add ~/.ssh/id_rsa

如果出现

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.

那么需要输入

eval `ssh-agent -s`

出现

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ eval `ssh-agent -s`
Agent pid 1595

再输入

ssh-add ~/.ssh/id_rsa

出现

saury@LAPTOP-JTM5BLC4 MINGW64 /e/simulink/PDS/pds_simulink
$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/saury/.ssh/id_rsa (**********@**.com)

操作以上两步后重新输入,查看公钥生成路径

ssh-add ~/.ssh/id_rsa

第五步

根据第四步中生成的SSH公钥路径信息,找到id_rsa.pub,用文本方式打开,将里面的内容全部复制。

复制完成后,进入github或者Gitee(码云),登录账号,按如下步骤进心操作:

新建公钥:title可以任意,把复制的内容粘贴进key中,生成


最后

会收到github发来的邮件,提示一个公钥被添加到你的账户中。

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值