» SSH

Command: vagrant ssh [name|id] [— extra_ssh_args]

This will SSH into a running Vagrant machine and give you access to a shell.

On a simple vagrant project, the instance created will be named default.

Vagrant will ssh into this instance without the instance name:

  1. $ vagrant ssh
  2. Welcome to your Vagrant-built virtual machine.
  3. Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
  4. $ logout
  5. Connection to 127.0.0.1 closed.

Or you could use the name:

  1. $ vagrant ssh default
  2. Welcome to your Vagrant-built virtual machine.
  3. Last login: Fri Jul 20 15:09:52 2018 from 10.0.2.2
  4. $ logout
  5. Connection to 127.0.0.1 closed.
  6. $

On multi-machine setups, you can login to each vm using the name as displayedon vagrant status

  1. $ vagrant status
  2. Current machine states:
  3. node1 running (virtualbox)
  4. node2 running (virtualbox)
  5. This environment represents multiple VMs. The VMs are all listed
  6. above with their current state.
  7. $ vagrant ssh node1
  8. Welcome to your Vagrant-built virtual machine.
  9. Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
  10. vagrant@precise64:~$ logout
  11. Connection to 127.0.0.1 closed.
  12. $ vagrant ssh node2
  13. Welcome to your Vagrant-built virtual machine.
  14. Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
  15. vagrant@precise64:~$ logout
  16. Connection to 127.0.0.1 closed.
  17. $

On a system with machines running from different projects, you could use the idas listed in vagrant global-status

  1. $ vagrant global-status
  2. id name provider state directory
  3. -----------------------------------------------------------------------
  4. 13759ff node1 virtualbox running /Users/user/vagrant/folder
  5. The above shows information about all known Vagrant environments
  6. on this machine. This data is cached and may not be completely
  7. up-to-date (use "vagrant global-status --prune" to prune invalid
  8. entries). To interact with any of the machines, you can go to that
  9. directory and run Vagrant, or you can use the ID directly with
  10. Vagrant commands from any directory.
  11. $ vagrant ssh 13759ff
  12. Welcome to your Vagrant-built virtual machine.
  13. Last login: Fri Jul 20 15:19:36 2018 from 10.0.2.2
  14. vagrant@precise64:~$ logout
  15. Connection to 127.0.0.1 closed.
  16. $

If a (two hyphens) are found on the command line, any arguments afterthis are passed directly into the ssh executable. This allows you to passany arbitrary commands to do things such as reverse tunneling down into thessh program.

» Options

  • -c COMMAND or —command COMMAND - This executes a single SSH command, printsout the stdout and stderr, and exits.

  • -p or —plain - This does an SSH without authentication, leavingauthentication up to the user.

» SSH client usage

Vagrant will attempt to use the local SSH client installed on the host machine. OnPOSIX machines, an SSH client must be installed and available on the PATH.

For Windows installations, an SSH client is provided within the installerimage. If no SSH client is found on the current PATH, Vagrant will use theSSH client it provided. Depending on the local environment used for runningVagrant, the installer provided SSH client may not work correctly. For example,when using a cygwin or msys2 shell the SSH client will fail to work as expectedwhen run interactively. Installing the SSH package built for the current workingenvironment will resolve this issue.

» Background Execution

If the command you specify runs in the background (such as appending a & toa shell command), it will be terminated almost immediately. This is becausewhen Vagrant executes the command, it executes it within the context of ashell, and when the shell exits, all of the child processes also exit.

To avoid this, you will need to detach the process from the shell. PleaseGoogle to learn how to do this for your shell. One method of doing this isthe nohup command.

» Pageant on Windows

The SSH executable will not be able to access Pageant on Windows. WhileVagrant is capable of accessing Pageant via internal libraries, theSSH executable does not have support for Pageant. This means keysfrom Pageant will not be available for forwarding when using thevagrant ssh command.

Third party programs exist to allow the SSH executable to access Pageantby creating a unix socket for the SSH executable to read. For more informationplease see ssh-pageant.