I would like to reproduce the way how Vagrant logs to my VM within a shell script using ssh
command, so I create an alias to my Vagrant instance.
What is the command syntax to use the regular ssh
command to access it?
I would like to reproduce the way how Vagrant logs to my VM within a shell script using ssh
command, so I create an alias to my Vagrant instance.
What is the command syntax to use the regular ssh
command to access it?
If you just want to set it up so you can use normal the normal ssh commandline, as well as scp and such, you can run
vagrant ssh-config
and append the output to your default ssh configuration. If you replace the line "Host default" with a more descriptive hostname, you should be good to go.You can take any of the
ssh-config
arguments, and pass them to ssh on the commandline as-o Key=value
. So, for a simple one-host vagrant setup (you might have to do a little more work withgrep
orperl
for a multihost setup), you can do something like the following (or replaceperl
withsed
if you want):There's a lot of answers already, but they all seem overly complicated or solve problems the asker didn't have.
simply:
If you don't need to use stdin with
ssh
(for example you want to execute just a command and logout) you could use:This method was suggested in response to a similar question on google groups.
Unfortunately bash process substitution doesn't work either (see this question on unix.stackexchange for more details).
The best options you have, if you want an interactive shell, are to create a temp file and use that with
ssh -F
or useawk
as suggested by the other answers.I've had to re-implement "vagrant ssh" because it's
-c
option didn't pass on arguments properly. This is basically what it does (there might be more, but it works fine this way)As a one-liner (with thanks to kgadek):
To account for when you have more than one vagrant host, this will select the desired host, as well as cull blank lines from the config (using sed):
ssh vagrant@<host>
password:vagrant
Examples:
ssh vagrant@vagrant.local
or after checking the IP (from the inside, using
vagrant ssh
)ssh vagrant@172.28.128.3