大网数据广告活动
服务器运维问答

How to configure SSH for Vagrant environment?

· 52CE 我爱测

I prepared a cluster of 4VM's with this Vagrantfile. hosts = { "n1" => "192.168.77.10", "n2" => "192.168.77.11", "n3" => "192.168.77.12", "n4" => "192.168.77.13" } Vagrant.configure("2") do |config| # always use Vagrants insecure…

问题原文

原帖链接 · Richard Rublev · CC BY-SA 4.0

I prepared a cluster of 4VM's with this Vagrantfile.

hosts = {
"n1" => "192.168.77.10",
"n2" => "192.168.77.11",
"n3" => "192.168.77.12",
"n4" => "192.168.77.13"
}

Vagrant.configure("2") do |config|
# always use Vagrants insecure key
    config.ssh.insert_key = false
# forward ssh agent to easily ssh into the different machines
    config.ssh.forward_agent = true
    check_guest_additions = false
    functional_vboxsf = false
    config.vm.box = "ubuntu/bionic64"

    hosts.each do |name, ip|
     config.vm.define name do |machine|
      machine.vm.network :private_network, ip: ip
      machine.vm.provider "virtualbox" do |v|
       v.name = name
      end
     end
    end
end

Now I have four running virtual machines. After vagrant ssh n4,my next step is to ssh to other machines,but I can not manage. I tried this

vagrant ssh [email omitted]
The machine with the name '[email omitted]' was not found configured for
this Vagrant environment.

I already posted question regarding denied permission

ssh [email omitted]
[email omitted]: Permission denied (publickey).

This example is from Mastering Kubernetes book.(Gigi Sayfan) I am not sure if I have permissions problem or something else. I can not find similar examples.

I tried then

vagrant@ubuntu-bionic:~$ vagrant ssh vagrant@n1
The machine with the name 'vagrant@n1' was not found configured for
this Vagrant environment.

This does not work either

vagrant@ubuntu-bionic:~$ ssh vagrant@n1
ssh: Could not resolve hostname n1: Temporary failure in name resolution

I really do not understand what is going on.

My config

vagrant ssh-config
Host n1
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/miki/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

Host n2
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/miki/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

Host n3
  HostName 127.0.0.1
  User vagrant
  Port 2201
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/miki/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

Host n4
  HostName 127.0.0.1
  User vagrant
  Port 2202
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/miki/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

If I try

ssh -vvv vagrant@n1
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /home/vagrant/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "n1" port 22
ssh: Could not resolve hostname n1: Temporary failure in name resolution

Gerald suggested this

vagrant ssh n1

Output

The machine with the name 'n1' was not found configured for
this Vagrant environment.

已采纳解答

原帖链接 · Justin Chou · CC BY-SA 4.0

  1. In your vagrant up folder, use vagrant ssh n1

  2. It seems that you are using the default ssh key with config.ssh.insert_key = false setting, then use ssh [email omitted] -i ~/.vagrant.d/insecure_private_key might work for you.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-05-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。