0
我有一個vagrant
VM正在運行。Net :: SSH.start超時連接到Ruby中的Vagrant主機
vagrant init centos/7
產生最小Vagrantfile
:
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
end
vagrant ssh-config
報告如下:
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile "/path/to/.vagrant/machines/default/virtualbox/private_key"
IdentitiesOnly yes
LogLevel FATAL
但是,下面好像失敗:
require 'net/ssh'
Net::SSH.start("127.0.0.1", "vagrant", {
:auth_methods => [
"publickey",
"password"
],
:port=>"2222",
:keys => [
"/path/to/.vagrant/machines/default/virtualbox/private_key"
]
})
w ^第i個以下:
Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout
from /usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/transport/session.rb:90:in `rescue in initialize'
from /usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/transport/session.rb:57:in `initialize'
from /usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh.rb:233:in `new'
from /usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh.rb:233:in `start'
from (irb):2
from /usr/local/bin/irb:11:in `<main>'
我可以使用SSH連接,符合市場預期:
ssh -p 2222 -i /path/to/.vagrant/machines/default/virtualbox/private_key [email protected]
我怎樣才能連接到在Ruby中vagrant
主機我的本地機器上?