git@github.com: Permission denied (publickey).

        本地虚拟机ubuntu上安装git,想从github上拉取项目到ubuntu上的过程。

1、在ubuntu上安装git

        更新apt指令

sudo apt update

        安装git

sudo apt install git

        查看安装git版本

git --version

2、ssh认证

        首先已经安装了ssh指令

        先执行

ssh -T git@github.com
执行之后提示:Permission denied (publickey).

        接下来通过Ubuntu下的ssh-keygen命令创建公钥/私钥对:(使用你注册github时的邮箱)

ssh-keygen -C "1450053947@qq.com" -f ~/.ssh/github

        会得到下面提示

root@ljy-virtual-machine:~# ssh-keygen -C "1450053947@qq.com" -f ~/.ssh/github
Generating public/private rsa key pair.
/root/.ssh/github already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/github
Your public key has been saved in /root/.ssh/github.pub
The key fingerprint is:
SHA256:i8oSSUf/SVLNw2zPPx2FO55vq2S1b2787gtXOZ/hR4s 1450053947@qq.com

        去/root/.ssh下查看

root@ljy-virtual-machine:~# ls ~/.ssh
github  github.pub  known_hosts

        发现有刚才生成的私钥github和公钥github.pub

        查看公钥,并将公钥复制到github的框里(下图红框里的内容复制到github框里)

cat /root/.ssh/github.pub

 

 

git@github.com: Permission denied (publickey).

         此时在运行指令

ssh -T git@github.com

        如果提示让输入yes就输入yes,然后再次执行上面的指令。

        如果此时仍然提示

git@github.com: Permission denied (publickey).

        那么可使用下面指令进行调试

ssh -T -v git@github.com

        得到信息为:

root@ljy-virtual-machine:~# ssh -T -v git@github.com
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to github.com [20.205.243.166] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: Remote protocol version 2.0, remote software version babeld-2aa8e17d
debug1: no match: babeld-2aa8e17d
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
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: Server host key: ecdsa-sha2-nistp256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM
debug1: Host 'github.com' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
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: /root/.ssh/id_rsa 
debug1: Will attempt key: /root/.ssh/id_dsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /root/.ssh/id_ed25519 
debug1: Will attempt key: /root/.ssh/id_ed25519_sk 
debug1: Will attempt key: /root/.ssh/id_xmss 
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: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug1: Trying private key: /root/.ssh/id_xmss
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

        看以上信息发现是

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug1: Trying private key: /root/.ssh/id_xmss
debug1: No more authentication methods to try.

        这几个的问题,意思是一直在尝试获取/root/.ssh/id_rsa      /root/.ssh/id_dsa

        使用指令,发现没有id_rsa 和id_dsa

root@ljy-virtual-machine:~# ls ~/.ssh
github  github.pub  known_hosts

        因此来到/root/.ssh下

cd ~/.ssh

        使用下面指令,copy它们两个

root@ljy-virtual-machine:~/.ssh# cp github id_rsa && cp github.pub id_rsa.pub

        再次执行命令

ssh -T git@github.com

得到提示信息:

Hi liujianyon1! You've successfully authenticated, but GitHub does not provide shell access.

3、总结

        以上就是整个配置git的内容,可能写的不是很仔细,认真看应该没问题,看好你!!!嘻嘻

借鉴博客:

Ubuntu下使用git提交代码至GitHub - 走看看

关于ssh连接主机,git连接github失败的问题:ssh -T git@github.com&&Permission denied (publickey)_SunnyPotter的博客-CSDN博客

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当你在使用命令ssh -T git@github.com测试公钥是否添加成功时,出现了报错"git@github.com: Permission denied (publickey)",以及在执行命令git push -u origin master时出现了错误提示"gitt@github.com: Permission denied (publickey). fatal: Could not read from remote repository",这通常是因为你本地或服务器上没有生成SSH key所导致的。SSH key是一种用于身份验证的加密密钥对,它包括了公钥和私钥两部分。在使用GitGitHub进行通信时,需要将生成的公钥添加到GitHub账户中,以便进行身份验证。 为了解决这个问题,你需要执行以下步骤: 1. 检查你的电脑上是否已经生成了SSH key。你可以通过运行命令"ls -al ~/.ssh"来查看。如果有一个名为id_rsa.pub或id_dsa.pub的文件,那么说明你已经生成了SSH key。 2. 如果没有生成SSH key,你需要使用以下命令生成一个新的SSH key: ssh-keygen -t rsa -b 4096 -C "your_email@example.com" 这里的"your_email@example.com"应该替换成你在GitHub上注册的电子邮件地址。 3. 在生成SSH key后,你需要将公钥添加到你的GitHub账户中。你可以使用以下命令将公钥复制到剪贴板: pbcopy < ~/.ssh/id_rsa.pub 然后登录GitHub账户,转到"Settings" -> "SSH and GPG keys" -> "New SSH key",将公钥粘贴到"Key"字段中,然后点击"Add SSH key"按钮保存。 现在,当你再次执行命令ssh -T git@github.comgit push -u origin master时,应该不再出现"Permission denied (publickey)"的错误提示了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Git错误记录 — git@github.com: Permission denied (publickey)](https://blog.csdn.net/baidu_40188909/article/details/108407895)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [MAC电脑gitt@github.com: Permission denied (publickey). fatal: Could not read from remote repository](https://blog.csdn.net/weixin_44468956/article/details/125293590)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值