Re: How to replace the default ssh port forward?

6,746 views
Skip to first unread message

Aaron Aaron

unread,
Apr 7, 2013, 11:43:26 PM4/7/13
to vagra...@googlegroups.com
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,

Reply all
Reply to author
Forward
0 new messages