How to ssh to vagrant without actually running “va

2019-01-07 01:54发布

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?

15条回答
Anthone
2楼-- · 2019-01-07 02:39

You can add ssh config for your vagrant host to ssh config.

  1. Get ssh config for vagrant machine in vagrant folder: vagrant ssh-config

  2. Open {UserDir}/.ssh/config and append there result from the previous command. Note: the first line Host default mean the alias which you will use later for ssh command. Name it as your vagrant machine or dir. If you have only one vagrant dir - you can name it Host vagrant

  3. Ssh to vagrant: ssh vagrant. The last name is alias from the previous step.

查看更多
虎瘦雄心在
3楼-- · 2019-01-07 02:43

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.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-07 02:46

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.

The ssh executable found in the PATH is a PuTTY Link SSH client. Vagrant is only compatible with OpenSSH SSH clients.

However, in Windows 10 we also have Bash on Ubuntu on Windows. So, I just use that with the following command:

ssh vagrant@127.0.0.1 -p2222 -i .vagrant/machines/default/virtualbox/private_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=Fatal

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 get

Permission denied (publickey,password).

I'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.

查看更多
登录 后发表回答