简体   繁体   中英

SSH Vagrant VM from Android

This is the Vagrant file I've got:

VAGRANTFILE_API_VERSION = "2"
PROJECTS_HOME = ENV['PROJECTS_HOME'] || "../"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "public_network", ip: "192.168.8.120"
  config.vm.network :forwarded_port, guest: 443, host: 443
  config.vm.network :forwarded_port, guest: 443, host: 4443
  config.vm.network :forwarded_port, guest: 80, host: 8080
  config.vm.hostname = "node1"
  if PROJECTS_HOME
    config.vm.synced_folder PROJECTS_HOME, "/srv/projects"
  end
  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end
  config.vm.provision "shell", inline: <<SCRIPT
#cd /vagrant && make all
SCRIPT
end

Then if I want to SSH it trough PuTTY it works fine when I type ssh vagrant@127.0.0.1 . However, I also downloaded SSH client on my Android device, which is running Ginger Bread and it's connected to the same network.

My question is how do I ssh vagrant from Android?

I have already tried all of the following:

ssh vagrant@192.168.8.120

ssh vagrant@127.0.0.1

ssh vagrant@10.0.2.15

在此处输入图片说明

If someone can explain how should I do it, it will be highly appreciated :)

Vagrant typically uses the external port 2222 mapped to the internal 22 port. You can open VirtualBox's network adapter settings for that box to verify that, though.

Your ssh command without a port number is using port 22, you need to connect to port 2222 with the -p flag like so

ssh -p 2222 vagrant@IP

Also, Virtualbox is only forwarding on localhost ( 127.0.0.1 ), open that to the public by changing it to 0.0.0.0 for the Host IP and clear out the Guest IP field.

To automatically forward guest 22 port to 2222 from your host machine and then be available to ssh from any ip you can add the following into your Vagrantfile definition

config.vm.network :forwarded_port, guest: 22, host: 2222, host_ip: "0.0.0.0", id: "ssh", auto_correct: true

Then you can access your VM using your local host IP - make sure to download the private key into your android device and add -i option or you will be prompt to enter the password

ssh -p 2222 vagrant@<host_IP_on_the_network> -i <path_to_private_key>

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