繁体   English   中英

构建后无法将 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. sudo 命令是否应该与 Git 一起使用?

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

  1. 检查您是否连接到正确的服务器

运行$ ssh -vT git@github.com在端口 22 上建立连接并返回You've successfully authenticated

  1. 始终使用“git”用户

我使用 set-url 命令将 repo 更改为使用 SSH 协议,然后ssh -T git@github.com返回:

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. 确保您有正在使用的密钥

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

这里有一个问题:

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

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

每次尝试运行构建和推送时,我都会遇到权限被拒绝(公钥)。 我根据 Vue 文档中的本指南创建了一个 .deploy.sh 文件,并取消注释并在用于 github.io 推送的行上添加了我的用户名https://cli.vuejs.org/guide/deployment.html#github-页

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运行它时它返回

 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

请问有人可以帮助我吗?

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

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

export GIT_SSH_COMMAND='ssh -Tv'

并运行您的脚本。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM