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?
You can add ssh config for your vagrant host to ssh config.
Get ssh config for vagrant machine in vagrant folder:
vagrant ssh-config
Open
{UserDir}/.ssh/config
and append there result from the previous command. Note: the first lineHost default
mean the alias which you will use later forssh
command. Name it as your vagrant machine or dir. If you have only one vagrant dir - you can name itHost vagrant
Ssh to vagrant:
ssh vagrant
. The last name is alias from the previous step.My Env. is Win7 + Centos. The answer with most agreement doesn't work for me. After failing after trying
ssh -p [port] [usrname]@127.0.01
, I just use XShell to add a new session with the vagrant port and user name.It works.
Maybe Xshell is a candinate.
A lot of the other answers assume you have Vagrant installed.
I have Vagrant installed on Windows 10, but I can't
vagrant ssh
because I'm using PuTTy as my SSH client, which vagrant won't accept.However, in Windows 10 we also have Bash on Ubuntu on Windows. So, I just use that with the following command:
It's easy enough to install Vagrant on Win10-Ubuntu but it also wants you to install Virtualbox for some reason, which I'd rather not do.
N.B. I've tried with the
ssh default -F vagrant-ssh-config
method, but I just getI'm guessing this is because the
IdentityFile
path is a Windows path, whereas in Bash, it should begin with/mnt/c/
. I suppose you could just write out the file and then modify it if that works better for you.