Skip to content

Instantly share code, notes, and snippets.

@aubricus
Last active December 12, 2015 03:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aubricus/4711167 to your computer and use it in GitHub Desktop.
Save aubricus/4711167 to your computer and use it in GitHub Desktop.
Windows, Vagrant ssh snippet
:: Windows / Vagrant ssh snippet
:: Gotcha: Calling "ssh" from the windows CMD.exe requires Cygwin installed and
:: added to the PATH. This allows me to use the ssh port, but does not
:: require that I run this batch through Cygwin.
:: Notes:
:: The Vagrant convenience "vagrant ssh" doesn't work on windows.
:: One is left to manually ssh into the virtual box, which can be cumbersome.
:: Additionally, always connecting using "localhost" as the host will result in a
:: "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED" error.
:: see: http://www.cyberciti.biz/faq/warning-remote-host-identification-has-changed-error-and-solution/
:: To solve that problem and avoid clearing out ssh keys and / or deleting
:: the "known_hosts" file, I find it convenient to add an entry to
:: my "hosts" file; e.g., "127.0.0.1 my-site.ssh".
:: Note the convention of adding a ".ssh" to the host entry.
:: I'm usually in the hosts file to add an "127.0.0.1 my-site.dev"
:: entry so the effort amounts to a simple copy / paste / edit.
:: Command
:: ssh vagrant@HOST.ssh -p[PORT]
:: Parameters
:: HOST
::required
:: entry in your host file preceding the ".", e.g. [my-site].ssh
:: PORT
:: optional
:: defaults to 2222
:: the ssh port you wish to use
:: Example, Basic
:: C:\>vagrant-ssh my-site
:: Example, with PORT configured
:: C:\>vagrant-ssh my-site 1234
:: ProTip
:: Add the location of this script to your PATH to call it from any directory.
@ECHO OFF
SET HOST=%1
SET PORT=%2
IF [%2]==[] SET PORT=2222
ssh vagrant@%HOST%.ssh -p%PORT%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment