Capistrano Error语言 - Net::SSH::HostKeyMismatch



我对Capistrano和Ruby完全陌生,似乎无法设置基本的部署。每次我运行cap-deploy:检查时,我都会得到以下错误:

服务器:["domain.com"]连接失败:me@domain.com(Net::SSH::HostKeyMismatch:指纹0c:de:d4:1b:e9:64:83:3a:8b:d7:c3:42:98:5b:5d:8c与"[domain.com]:22,[62.39.12]:22"不匹配)

我的deploy.db如下所示:

set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
set :application, "captest" # TODO
set :repository, "git@bitbucket.org:jy312/captest.git" # TODO
set :scm, :git
set :use_sudo, false
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :deploy_via, :remote_cache
set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules"]
set :git_enable_submodules, 1

我尝试将我的本地计算机公钥(id_rsa.pub)添加到服务器上的known_hosts列表中,但没有成功。

如有任何建议,我们将不胜感激。非常感谢你的帮助。

目标服务器的指纹与本地known_hosts文件中的指纹不匹配。删除本地known_hosts文件中的现有条目。

您也可以尝试通过直接对服务器进行SSH而不是通过ruby来解决这个问题,因为这是一个SSH问题。

或通过(更改服务器的用户名和IP)重写:

$ ssh-keygen -f "/home/USERNAME/.ssh/known_hosts" -R 178.X.X.X

然后进入服务器

$ ssh user@178.X.X.X

并回答yes

重试部署

祝你好运;)

虽然不适合生产系统,但如果在部署到本地开发环境时遇到此问题,可以考虑告诉Capistrano忽略严格的主机密钥验证。

deploy.rb

set :ssh_options, paranoid: false

https://github.com/net-ssh/net-ssh/blob/e90551a4672587e294b47f824a401550f55184cc/lib/net/ssh.rb#L160

场景:从源机器到目标机器的SSH

如果以上场景抛出Net::SSH::HostKeyMismatch,则执行以下操作,

1) Login to source machine and sudo su <User>
2) ssh destination machine
3) in step2, HostKeyMismatch error will be displayed and also the known hosts location.
or
2) cd ~
3) cd .ssh
4) vim known_hosts
5) clear the content of the file and save and quit (using command - :wq)

这应该能解决问题。

deploy.rb

set :ssh_options, {verify_host_key: :never}

最新更新