git gh-pages 部署权限错误“权限被拒绝(公钥)。致命:无法从远程存储库读取”

git gh-pages 部署权限错误“权限被拒绝(公钥)。致命:无法从远程存储库读取”

编辑:可能修复

除了提交的答案之外,任何遇到此错误/相同问题的人也可以尝试运行该命令$ ssh-add ~/.ssh/id_rsa。每当我需要传递此错误时,这似乎对我都有效!


我对使用 git 还很陌生,之前从未部署过 gh-pages,所以我不确定我做错了什么。我将主页、依赖项和脚本放入文件中,package.json运行时$ yarn run deploy一切都正常,直到最后。它告诉我它已准备好部署到我想要的页面,然后它给了我这个错误:

克隆到'node_modules/gh-pages/.cache/[电子邮件保护]!emilybossiere!GrabBag.git'...
权限被拒绝(公钥)。
致命:无法从远程存储库读取。

我已按照 GitHub 说明进行操作这个特定的错误,这让我想到这一页关于检查 SSH 密钥。我在处理应用程序的整个过程中都成功推送到此存储库,因此我知道它已通过身份验证并且可以正常工作,但由于某种原因,部署不起作用。

这是我运行时的输出$ ssh -vT [email protected]

OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: Connection established.
debug1: identity file /Users/emilybo/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/emilybo/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version babeld-80573d3e
debug1: no match: babeld-80573d3e
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: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/emilybo/.ssh/known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/emilybo/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.255.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Hi emilybossiere! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2724, received 2236 bytes, in 0.1 seconds
Bytes per second: sent 31128.3, received 25551.7
debug1: Exit status 1

因此,它似乎连接得很好,所以当我这样做时,它会按应有的方式$ eval "$(ssh-agent -s)"返回,但是当我运行时,它会告诉我这是否意味着它实际上没有经过身份验证?> Agent pid 59566$ ssh-add -l -E md5The agent has no identities.

另外,步骤 2这一页说了一些关于自动将密钥加载到 ssh 代理的内容,但我以前从未这样做过,而且我不确定如何修改我的~/.ssh/config文件,但我似乎甚至没有一个?如果不存在此文件,我该如何修改它? :(

答案1

如果您收到此错误并且使用密码进行 git 身份验证,那么此解决方案可能适合您:

  1. cd ~ 并打开一个名为 .bashrc 的文件并添加以下行
eval `ssh-agent -s`
ssh-add

这假设您的密钥位于常规的 ~/.ssh/id_rsa 位置。如果不是,请在 ssh-add 命令后添加完整路径。

添加或创建文件 ~/.ssh/config 并添加内容

ForwardAgent yes
  1. 重新启动终端(您可能需要先重新启动系统)

  2. 系统将提示你输入密码

  3. 现在尝试npm run deploy

答案2

对于 Windows 用户,修复方法如下:

  1. 编辑C:\Users\YOUR_USER\.ssh\config
  2. 添加到配置文件:
Host github.io
  AddKeysToAgent yes
  IdentityFile C:\Users\YOUR_USER\.ssh\your_key.pub
  1. 从 Git Bash 而不是 IDE 的终端运行部署,否则您将不会收到密码提示。

相关内容