简体   繁体   中英

Permission denied message when attempting ssh to Vagrant public network IP from second machine on same network

I've combed the Internet clean for this one and still can't figure it out. I have a Vagrant VM running using VirtualBox, with the following Vagrantfile:

Vagrant.configure("2") do |config|
     config.vm.box = "ubuntu/xenial64"
     config.vm.network "public_network"

     config.vm.provider "virtualbox" do |vb|
          vb.memory = "1024"
          vb.gui = true
     end
end

Vagrant launches successfully, and I can run vagrant ssh successfully and get into the box. I can view the IP of the Vagrant public network, and I'm successfully hosting two Nginx sites in the box, which I can view from a different computer on the same network by visiting the IP of the Vagrant public network.

My server is a clunky laptop, so I want to ssh directly into the Vagrant box that's running on it (from a different development machine). I specifically want to edit the files on the server remotely using the VS Code remote dev tool. I can't for the life of me figure out why, when I run

ssh vagrant@[IP of Vagrant public network on the server]

it gives me "Permission denied (publickey)." It throws this both when I try to run it on the server itself and from another machine on the network.

Do I need to modify some ssh config file somewhere?

EDIT: I read this article, which recommended adding something like this to the ssh config file on the client machine:

    Host 192.168.100.100 <- Vagrant box network IP
      StrictHostKeyChecking no
      UserKnownHostsFile /dev/null
      IdentitiesOnly yes
      User vagrant
      IdentityFile /your/user/directory/.vagrant.d/insecure_private_key
      PasswordAuthentication no

this didn't work for me; instead of throwing "Permission denied," it just hangs.

Figured it out. I needed a copy of the private key from my [working dir]/.vagrant/machines/default/virtualbox/private_key file on my server. Once I scp'd that onto my secondary machine, I passed it to ssh as the IdentityFile:

ssh -I [location of copied private_key file] vagrant@[IP of Vagrant public network on the server]

and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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