How to replace the default ssh port forward?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to replace the default ssh port forward?

Aaron Aaron
How do I replace the default ssh port forward entirely?
I would prefer to be able to do this in a Vagrantfile that comes with a base box,
rather than making a new base box configured as such.
In other words, I get a base box with the default forward,
and I can replace the forward in the Vagrantfile of any
project based on that base box.

Vagrant version 1.1.4
Ubuntu 12.10 host and guest.

config.vm.network :forwarded_port, guest: 22, host: 2201

This creates the forward, but in addition to the default 2222.
After vagrant up, I can use ssh directly to ssh into the VM using either 2201 or 2222.
vagrant ssh uses 2222.

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: How to replace the default ssh port forward?

Aaron Aaron
OK, I found a way. I don't know Ruby or Vagrant well, so this may not be the way. Is there a better way?

I cloned vagrant from git-hub and went looking around.
In vagrant/config/default.rb there is code that looks very much like the configuration in Vagrantfile.
Including this:

  # Share SSH locally by default
  config.vm.network :forwarded_port,
    guest: 22,
    host: 2222,
    id: "ssh",
    auto_correct: true

So I copied that into my Vagrantfile, after config.vm.box, and changed it like so:

  config.vm.box = "ubu1210-64"

  # Share SSH locally by default
  config.vm.network :forwarded_port,
    guest: 22,
    host: 2201,
    id: "ssh",
    auto_correct: true

Thant does the trick. vagrant up reports:

[default] -- 22 => 2201 (adapter 1)

And vagrant ssh -- -v reports:

...
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2201.
...
Warning: Permanently added '[127.0.0.1]:2201' (ECDSA) to the list of known hosts.

I cannot ssh into port 2222 (which is the way I want it), but I can ssh to port 2201 (also the way I want it).

ssh -l vagrant -p 2222 localhost
ssh: connect to host localhost port 2222: Connection refused

ssh -l vagrant -p 2201 localhost
vagrant@localhost's password: 
Last login: Sun Apr  7 21:28:47 2013 from 10.0.2.2
vagrant@vagrant-ubuntu-1210:~$

On Sunday, April 7, 2013 5:58:17 PM UTC-6, Aaron Aaron wrote:
How do I replace the default ssh port forward entirely?
I would prefer to be able to do this in a Vagrantfile that comes with a base box,

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.