繁体   English   中英

Capistrano rails 应用程序部署失败。 服务器无法向 Github 识别自我。 权限被拒绝(公钥)

[英]Capistrano rails app deploying fails. Server can't identificate self to Github. Permission denied (publickey)

我正在尝试使用 Capistrano 将我的 rails 应用程序部署到服务器。

在我的本地,我运行了“ cap production deploy ”,然后出现错误。

    12: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run'
    11: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
    10: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/capistrano-3.11.2/lib/capistrano/scm/tasks/git.rake:18:in `block (3 levels) in eval_rakefile'
     9: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:100:in `with'
     8: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/capistrano-3.11.2/lib/capistrano/scm/tasks/git.rake:19:in `block (4 levels) in eval_rakefile'
     7: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/capistrano-3.11.2/lib/capistrano/scm/git.rb:38:in `check_repo_is_reachable'
     6: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/capistrano-3.11.2/lib/capistrano/scm/git.rb:77:in `git'
     5: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:80:in `execute'
     4: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
     3: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `tap'
     2: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
     1: from /Users/rainbowtape/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/Users/-------------/.rvm/gems/ruby-2.6.5/gems/sshkit-1.20.0/lib/sshkit/command.rb:97:in `exit_status=': git exit status: 128 (SSHKit::Command::Failed)
git stdout: Nothing written
git stderr: git@github.com: Permission denied (publickey).

所以我去服务器端检查服务器是否可以与Github通信。 它调出它没有。

deploy@xx.xx.xx.xx:~$ ssh -vT git@github.com
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Deprecated option "useroaming"
debug1: Connecting to github.com [140.82.118.4] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/deploy/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version babeld-2e9d163d
debug1: no match: babeld-2e9d163d
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/deploy/.ssh/known_hosts:1
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: Trying private key: /home/deploy/.ssh/id_rsa
debug1: Trying private key: /home/deploy/.ssh/id_dsa
debug1: Trying private key: /home/deploy/.ssh/id_ecdsa
debug1: Trying private key: /home/deploy/.ssh/id_ed25519
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

请注意,我已经使用“ssh-copy-id”将本地公钥复制到服务器

deploy@xx.xx.xx.xx:~/.ssh$ ls -la
total 16
drwx------  2 deploy deploy 4096 Nov 27 01:55 .
drwxr-xr-x 10 deploy deploy 4096 Nov 27 05:18 ..
-rw-------  1 deploy deploy 3724 Nov 27 12:37 authorized_keys
-rw-r--r--  1 deploy deploy 1326 Nov 27 01:57 known_hosts

另外,我尝试将密钥添加到 ssh-agent。 但失败了。

deploy@xx.xx.xx.xx:~/.ssh$ eval "$(ssh-agent -s)"
Agent pid 4417
deploy@xx.xx.xx.xx:~/.ssh$ ssh-add ~/.ssh/authorized_keys
Error loading key "/home/deploy/.ssh/authorized_keys": invalid format

服务器端是否只有我的公钥。 对? 不是私钥。 我在正确的轨道上吗?

更新 1

随着@ZedTuX建议,

我在服务器端生成了另一个 ssh 密钥集。 并将公钥添加到 github repo,以便它可以读/写。 所以我在服务器端测试了 git pull 和 push 。 有用。 位仍然收到此错误。 当我尝试在本地部署时。

 DEBUG [1b7b3349]   error: could not lock config file config: Permission denied
 DEBUG [1b7b3349]   fatal: could not set 'remote.origin.url' to 'git@github.com:maskeduser1/repo1.git'

这对我来说没有意义,因为我什至可以--set-upstream到 Github。 为什么我收到这个错误?

我已经复制了我的本地公钥

这不是它的工作方式。

首先,不要使用您的开发 SSH 密钥部署到您的服务器。 这个key有读写权限,很危险。 如果有人介绍您的服务器,他将拥有对您的 Github 存储库源代码的完全读/写访问权限。

而是使用部署密钥(在 Github 上,“设置 > 部署密钥”)。 因此,您使用ssh-keygen在您的服务器上生成一个新的 SSH 密钥,然后在“部署密钥”页面中从您的服务器复制/传递公共 SSH 密钥。

之后,您应该能够部署。

更新

所以现在你有这个错误:

DEBUG [1b7b3349]   error: could not lock config file config: Permission denied
DEBUG [1b7b3349]   fatal: could not set 'remote.origin.url' to 'git@github.com:maskeduser1/repo1.git'

您能否显示以下输出:

  • whoami
  • ls -al ~/.ssh
  • ls -al /<Capistrano :deploy_to>/repo

对于 capistrano repo文件夹,请查看:deploy_to设置。 如果您没有更改它,它应该在/var/www/文件夹中。

暂无
暂无

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

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