• Git报错:git@github.com: Permission denied (publickey)


    1 错误信息

    输入指令ssh -T git@github.com测试SSH链接,出现如下报错:

    1. git@github.com: Permission denied (publickey,password,keyboard-interactive).
    2. git@github.com: Permission denied (publickey).
    3. git@github.com's password:,但是即是你输入的是正确的密码,依旧提示Permission denied, please try again.

    2 常规解决方法

    在网上搜索相关解决方案,可以查到基本上都是说公钥没有配置好,操作如下:

    1. 生成SSH keys:ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "your_email@example.com"
    2. 配置ssh-agent:ssh-agent bashssh-add ~/.ssh/id_rsa.github
    3. 如果是多账号,则生成config:touch ~/.ssh/config
    4. 在GitHub账号页面中:settings -> SSH and GPG keys -> New SSH key

    上述详细操作方法可以查阅其他博文,因为这不是本文的重点,很多人可能已经正确的配置了SSH keys,但已经无法正常链接SSH,可以看下面的解决方法。

    3 其他解决方法

    要测试通过 HTTPS 端口的 SSH 是否可行,请运行以下 SSH 命令:

    ssh -T -p 443 git@ssh.github.com
    
    • 1

    如果你看到:

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

    那么说明可以通过 HTTPS 443端口建立的 SSH 连接,接下来编辑~/.ssh/config文件(C:\Users\Admin\.ssh\config),若没有该文件,可以输入如下指令新建一个:

    touch ~/.ssh/config 
    
    • 1

    把下面内容填入该文件:

    Host github.com
        Port 443
        HostName ssh.github.com
        User git
        IdentityFile ~/.ssh/id_rsa.github
    
    • 1
    • 2
    • 3
    • 4
    • 5

    需要注意的是IdentityFile字段的值要是.ssh文件夹中的GitHub公钥文件名。再输入:

    ssh -T git@github.com
    
    • 1

    将看到:

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

    说明问题已经解决了。

  • 相关阅读:
    缓存空间优化实践
    LeetCode-61-旋转链表
    渣画质视频秒变清晰,“达芬奇”工具集帮你自动搞定
    STL的常用算法-查找 (20221130)
    docker保存镜像、打包tar、加载tar镜像
    微信小程序完整项目实战(前端+后端)
    类的成员之一:属性(field)
    Paparazzi: Surface Editing by way of Multi-View Image Processing
    js运算符
    LeetCode025之K 个一组翻转链表(相关话题:链表逆序)
  • 原文地址:https://blog.csdn.net/syzdev/article/details/126921031