构建后无法将 Vue CLI 应用程序推送到 github.io - 权限被拒绝(公钥)

Cannot push Vue CLI app to github.io after build - Permission denied (publickey)

我已经解决了问题 https://help.github.com/en/github/authenticating-to-github/error-permission-denied-publickey

  1. Should the sudo command be used with Git?

我没有将 sudo 与 git 命令一起使用

  1. Check that you are connecting to the correct server

运行 $ ssh -vT git@github.com 在端口 22 和 returns You've successfully authenticated

上建立连接
  1. Always use the "git" user

我已经使用 set-url 命令更改 repo 以使用 SSH 协议和 ssh -T git@github.com returns:

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [140.82.118.4] port 22.
debug1: Connection established.
debug1: identity file /home/warwick/.ssh/id_rsa type 0
debug1: identity file /home/warwick/.ssh/id_rsa-cert type -1
debug1: identity file /home/warwick/.ssh/id_dsa type -1
debug1: identity file /home/warwick/.ssh/id_dsa-cert type -1
debug1: identity file /home/warwick/.ssh/id_ecdsa type -1
debug1: identity file /home/warwick/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/warwick/.ssh/id_ed25519 type -1
debug1: identity file /home/warwick/.ssh/id_ed25519-cert type -1
debug1: identity file /home/warwick/.ssh/id_xmss type -1
debug1: identity file /home/warwick/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0p1 Ubuntu-6build1
debug1: Remote protocol version 2.0, remote software version babeld-17f81433
debug1: no match: babeld-17f81433
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: 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: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/warwick/.ssh/known_hosts:3
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: /home/warwick/.ssh/id_rsa RSA SHA256:XUyMmE8J489MaD9Ix/1xJdilSU4aH/F27hdhQubMQL4
debug1: Will attempt key: /home/warwick/.ssh/id_dsa 
debug1: Will attempt key: /home/warwick/.ssh/id_ecdsa 
debug1: Will attempt key: /home/warwick/.ssh/id_ed25519 
debug1: Will attempt key: /home/warwick/.ssh/id_xmss 
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 public key: /home/warwick/.ssh/id_rsa RSA SHA256:XUyMmE8J489MaD9Ix/1xJdilSU4aH/F27hdhQubMQL4
debug1: Server accepts key: /home/warwick/.ssh/id_rsa RSA SHA256:XUyMmE8J489MaD9Ix/1xJdilSU4aH/F27hdhQubMQL4
Enter passphrase for key '/home/warwick/.ssh/id_rsa': 
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([140.82.118.4]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = en_ZA.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi WNortier! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3452, received 2484 bytes, in 0.5 seconds
Bytes per second: sent 6930.1, received 4986.7
debug1: Exit status 1
  1. Make sure you have a key that is being used

我根据 https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account 创建了一个新的 public/private 组合键 Identity added: /home/warwick/.ssh/id_rsa (myemail@gmail.com)

这里有问题:

在终端中启动 eval "$(ssh-agent -s)" 并且 运行ning ssh-add -l 返回 The agent has no identities. 即使我刚添加它?

将对项目 src 文件所做的更改推送到 github 不会提示我输入密码,当我检查我的 github 设置时,我看到密钥已被使用.所以钥匙似乎在工作

我每次尝试 运行 构建和推送时都会进入 Permission denied (publickey)。我根据 Vue 文档中的本指南创建了一个 .deploy.sh 文件,并取消注释并在用于 github.io push https://cli.vuejs.org/guide/deployment.html#github-pages

的行中添加了我的用户名
set -e
npm run build
cd dist
git init
git add -A
git commit -m "deploy"
git push -f git@github.com:wnortier/wnortier.github.io.git master
cd -

但是当我 运行 它和 sh .deploy.sh 它 returns

 DONE  Compiled successfully in 2175ms                                  15:40:48
  File                                 Size               Gzipped

  dist/js/chunk-vendors.c4d3d4de.js    114.27 KiB         40.31 KiB
  dist/js/app.8b5fd9c9.js              6.99 KiB           2.90 KiB
  dist/css/app.35dcd38a.css            0.27 KiB           0.21 KiB

  Images and other types of assets omitted.

 DONE  Build complete. The dist directory is ready to be deployed.
 INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html

Initialized empty Git repository in /home/warwick/Projects/wnortier.github.io/dist/.git/
[master (root-commit) 74551eb] deploy
 8 files changed, 14 insertions(+)
 create mode 100644 css/app.35dcd38a.css
 create mode 100644 favicon.ico
 create mode 100644 img/logo.82b9c7a5.png
 create mode 100644 index.html
 create mode 100644 js/app.8b5fd9c9.js
 create mode 100644 js/app.8b5fd9c9.js.map
 create mode 100644 js/chunk-vendors.c4d3d4de.js
 create mode 100644 js/chunk-vendors.c4d3d4de.js.map
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.

git配置如下:

user.email=warwick.nortier@gmail.com
user.name=warwick
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/WNortier/wnortier.github.io.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name=warwick
user.email=warwick.nortier@gmail.com

请问有人可以帮助我吗?

在您的会话中设置 GIT_SSH_COMMAND(作为您,而不是 root)

export GIT_SSH_COMMAND='ssh -Tv'

还有运行你的脚本。

您将看到与问题中相同类型的调试日志。
如果不是,那意味着脚本不是 运行 您的配置文件环境设置,这可以解释为什么它在手动完成时在命令行中工作,而不是通过所述脚本。

事实证明我的 ssh 密钥一直都设置正确。
我已通过 运行ning 以下命令成功解决问题:sudo chown -R $USERNAME /home/<myusername> 它允许我在没有 [sudo] 的情况下 运行 部署脚本。