Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

networking - 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.

question from:https://stackoverflow.com/questions/65910262/permission-denied-message-when-attempting-ssh-to-vagrant-public-network-ip-from

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...