2013-09-03 18:08:28 +00:00
|
|
|
---
|
2016-01-19 18:08:53 +00:00
|
|
|
layout: "docs"
|
2013-09-06 16:50:43 +00:00
|
|
|
page_title: "vagrant ssh - Command-Line Interface"
|
2013-09-03 18:08:28 +00:00
|
|
|
sidebar_current: "cli-ssh"
|
2016-01-19 18:08:53 +00:00
|
|
|
description: |-
|
|
|
|
The "vagrant ssh" command is used to establish an SSH session into a running
|
|
|
|
virtual machine to give you shell access.
|
2013-09-03 18:08:28 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# SSH
|
|
|
|
|
2016-04-12 11:45:10 +00:00
|
|
|
**Command: `vagrant ssh [name|id] [-- extra_ssh_args]`**
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
This will SSH into a running Vagrant machine and give you access to a shell.
|
|
|
|
|
2018-07-20 15:20:59 +00:00
|
|
|
On a simple vagrant project, the instance created will be named default.
|
|
|
|
|
|
|
|
Vagrant will ssh into this instance without the instance name:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ vagrant ssh
|
|
|
|
|
|
|
|
Welcome to your Vagrant-built virtual machine.
|
|
|
|
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
|
|
|
|
$ logout
|
|
|
|
Connection to 127.0.0.1 closed.
|
|
|
|
```
|
2018-07-20 19:48:46 +00:00
|
|
|
|
2018-07-20 15:20:59 +00:00
|
|
|
Or you could use the name:
|
2018-07-20 19:48:46 +00:00
|
|
|
|
2018-07-20 15:20:59 +00:00
|
|
|
```bash
|
|
|
|
$ vagrant ssh default
|
|
|
|
|
|
|
|
|
|
|
|
Welcome to your Vagrant-built virtual machine.
|
|
|
|
Last login: Fri Jul 20 15:09:52 2018 from 10.0.2.2
|
|
|
|
$ logout
|
|
|
|
Connection to 127.0.0.1 closed.
|
|
|
|
$
|
|
|
|
```
|
|
|
|
|
|
|
|
On multi-machine setups, you can login to each vm using the name as displayed
|
|
|
|
on `vagrant status`
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ vagrant status
|
|
|
|
Current machine states:
|
|
|
|
|
|
|
|
node1 running (virtualbox)
|
|
|
|
node2 running (virtualbox)
|
|
|
|
|
|
|
|
This environment represents multiple VMs. The VMs are all listed
|
|
|
|
above with their current state.
|
|
|
|
$ vagrant ssh node1
|
|
|
|
|
|
|
|
Welcome to your Vagrant-built virtual machine.
|
|
|
|
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
|
|
|
|
vagrant@precise64:~$ logout
|
|
|
|
Connection to 127.0.0.1 closed.
|
|
|
|
$ vagrant ssh node2
|
|
|
|
|
|
|
|
Welcome to your Vagrant-built virtual machine.
|
|
|
|
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
|
|
|
|
vagrant@precise64:~$ logout
|
|
|
|
Connection to 127.0.0.1 closed.
|
|
|
|
$
|
|
|
|
```
|
|
|
|
|
|
|
|
On a system with machines running from different projects, you could use the id
|
|
|
|
as listed in `vagrant global-status`
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ vagrant global-status
|
|
|
|
id name provider state directory
|
|
|
|
-----------------------------------------------------------------------
|
|
|
|
13759ff node1 virtualbox running /Users/user/vagrant/folder
|
|
|
|
|
|
|
|
The above shows information about all known Vagrant environments
|
|
|
|
on this machine. This data is cached and may not be completely
|
|
|
|
up-to-date (use "vagrant global-status --prune" to prune invalid
|
|
|
|
entries). To interact with any of the machines, you can go to that
|
|
|
|
directory and run Vagrant, or you can use the ID directly with
|
2018-07-20 19:48:46 +00:00
|
|
|
Vagrant commands from any directory.
|
2018-07-20 15:20:59 +00:00
|
|
|
$ vagrant ssh 13759ff
|
|
|
|
|
|
|
|
Welcome to your Vagrant-built virtual machine.
|
|
|
|
Last login: Fri Jul 20 15:19:36 2018 from 10.0.2.2
|
|
|
|
vagrant@precise64:~$ logout
|
|
|
|
Connection to 127.0.0.1 closed.
|
|
|
|
$
|
|
|
|
```
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
If a `--` (two hyphens) are found on the command line, any arguments after
|
|
|
|
this are passed directly into the `ssh` executable. This allows you to pass
|
2013-12-19 12:23:18 +00:00
|
|
|
any arbitrary commands to do things such as reverse tunneling down into the
|
2013-09-03 18:08:28 +00:00
|
|
|
`ssh` program.
|
|
|
|
|
|
|
|
## Options
|
|
|
|
|
|
|
|
* `-c COMMAND` or `--command COMMAND` - This executes a single SSH command, prints
|
2015-04-26 00:22:10 +00:00
|
|
|
out the stdout and stderr, and exits.
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
* `-p` or `--plain` - This does an SSH without authentication, leaving
|
|
|
|
authentication up to the user.
|
2015-07-06 20:07:00 +00:00
|
|
|
|
2018-01-26 15:25:57 +00:00
|
|
|
## SSH client usage
|
|
|
|
|
|
|
|
Vagrant will attempt to use the local SSH client installed on the host machine. On
|
|
|
|
POSIX machines, an SSH client must be installed and available on the PATH.
|
|
|
|
|
|
|
|
For Windows installations, an SSH client is provided within the installer
|
|
|
|
image. If no SSH client is found on the current PATH, Vagrant will use the
|
|
|
|
SSH client it provided. Depending on the local environment used for running
|
|
|
|
Vagrant, 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 expected
|
|
|
|
when run interactively. Installing the SSH package built for the current working
|
|
|
|
environment will resolve this issue.
|
|
|
|
|
2015-07-06 20:07:00 +00:00
|
|
|
## Background Execution
|
|
|
|
|
|
|
|
If the command you specify runs in the background (such as appending a `&` to
|
|
|
|
a shell command), it will be terminated almost immediately. This is because
|
|
|
|
when Vagrant executes the command, it executes it within the context of a
|
|
|
|
shell, and when the shell exits, all of the child processes also exit.
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
To avoid this, you will need to detach the process from the shell. Please
|
2015-07-06 20:07:00 +00:00
|
|
|
Google to learn how to do this for your shell. One method of doing this is
|
|
|
|
the `nohup` command.
|