SSH 到 Windows 中的 Vagrant 框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9885108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSH to Vagrant box in Windows?
提问by Sathish
I'm using Vagrant to start a VirtualBox VM in windows. In other platforms, I can just
我正在使用 Vagrant 在 Windows 中启动 VirtualBox VM。在其他平台,我可以
$ vagrant ssh
to connect to the VM.
连接到虚拟机。
How do i connect to this Vagrant box in windows?
我如何在 Windows 中连接到这个 Vagrant 盒子?
The way suggested in Vagrant documentation to use PuTTy also did not work:
Vagrant 文档中建议的使用 PuTTy 的方式也不起作用:
http://docs-v1.vagrantup.com/v1/docs/getting-started/ssh.html
http://docs-v1.vagrantup.com/v1/docs/getting-started/ssh.html
回答by Dror Bereznitsky
I use PuTTY to connect to my Vagrant boxes on Windows7.
我使用 PuTTY 连接到 Windows7 上的 Vagrant 盒子。
Make sure you
确保你
- convert the
%USERPROFILE%\.vagrant.d\insecure_private_key
to .ppk using PuTTYGen - use the .ppk key in your PuTTY session - configured in Connection > SSH > Auth > Private key file
- use host
127.0.0.1
- use port 2222 instead of 22
- you can set the default username (vagrant) under Connection > SSH > Auth > Private key for authentication
%USERPROFILE%\.vagrant.d\insecure_private_key
使用PuTTYGen将其转换为 .ppk- 在 PuTTY 会话中使用 .ppk 密钥 - 在 Connection > SSH > Auth > Private key file 中配置
- 使用主机
127.0.0.1
- 使用端口 2222 而不是 22
- 您可以在 Connection > SSH > Auth > Private key for authentication 下设置默认用户名(vagrant)
回答by Michael Field
You must patchsome Vagrant code by modifying only one file, ssh.rb
.
你必须通过只修改一个文件来修补一些 Vagrant 代码,ssh.rb
.
All the info is here: https://gist.github.com/2843680
所有信息都在这里:https: //gist.github.com/2843680
vagrant ssh
will now work also in Windows, just like in Linux.
vagrant ssh
现在也可以在 Windows 中工作,就像在 Linux 中一样。
EDIT: In newer Versions this became unnecessary. You still have to add the path to your ssh.exe
to your PATH
Variable:
编辑:在较新的版本中,这变得不必要了。您仍然必须将路径添加ssh.exe
到您的PATH
Variable:
Search for ssh.exeon your computer, copy the Path (i.e. C:\Program Files (x86)\Git\bin
), open System Preferences, find the Environment variableSettings, click on the Path Variable, add the path, separating the existing paths using ;
.
在电脑上搜索ssh.exe,复制路径(即C:\Program Files (x86)\Git\bin
),打开系统偏好设置,找到环境变量设置,点击路径变量,添加路径,使用;
.
回答by gabrielhpugliese
Another option using git binaries:
使用 git 二进制文件的另一种选择:
- Install git: http://git-scm.com/download/win
- Start Menu > cmd (shift+enter to go as Administrator)
set PATH=%PATH%;C:\Program Files\Git\usr\bin
vagrant ssh
- 安装 git:http: //git-scm.com/download/win
- 开始菜单 > cmd(shift+enter 以管理员身份进入)
set PATH=%PATH%;C:\Program Files\Git\usr\bin
vagrant ssh
Hope this helps :)
希望这可以帮助 :)
Just a bonus after months using that on Windows: use Consoleinstead of the Win terminal, so you can always open a new terminal tab with PATH set (configure it on options)
在 Windows 上使用几个月后只是一个奖励:使用控制台而不是 Win 终端,因此您始终可以打开一个带有 PATH 设置的新终端选项卡(在选项上配置)
回答by Rafael Gorski
Download Putty: http://www.chiark.greenend.org.uk/~sgtatham/putty/
下载腻子:http: //www.chiark.greenend.org.uk/~sgtatham/putty/
Using putty.exe:
使用 putty.exe:
Putty GUI:
腻子图形用户界面:
HostName: 127.0.0.1
Port: 2222
When you connect(Terminal Screen):
连接时(终端屏幕):
User: vagrant
Passwd: vagrant
Before you try to connect, verify your VM using cmd.exe:
在尝试连接之前,请使用 cmd.exe 验证您的 VM:
vagrant status
If it is down use:
如果它是下来使用:
vagrant up
回答by begie
The accepted answeris really helpful however it may happen that instead of the following key:
该接受的答案是真正有用但它可能发生,而不是下面的键:
%USERPROFILE%\.vagrant.d\insecure_private_key
a different key has to be converted to the Putty's format:
必须将不同的密钥转换为 Putty 的格式:
{vagrant_machine_root}/.vagrant/machines/default/virtualbox/private_key
Where {vagrant_machine_root}
is a folder with the Vagrantfile
of the machine we want to connect to using Putty.
我们要使用 Putty 连接到的机器{vagrant_machine_root}
的文件夹在哪里Vagrantfile
。
As @ibizaman mentioned use vagrant ssh-config
to check what key is used by vagrant:
正如@ibizaman 提到的用于vagrant ssh-config
检查 vagrant 使用的密钥:
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile c:/dev/test/.vagrant/machines/default/virtualbox/private_key <-- HERE IS THE KEY YOU NEED TO CONVERT TO THE PUTTY FORMAT
IdentitiesOnly yes
LogLevel FATAL
回答by camilohe
Now you could also use the following plugin to connect using putty:
现在您还可以使用以下插件使用 putty 进行连接:
https://github.com/nickryand/vagrant-multi-putty
https://github.com/nickryand/vagrant-multi-putty
Just execute
只需执行
vagrant plugin install vagrant-multi-putty
vagrant 插件安装 vagrant-multi-putty
and make sure putty.exe and puttygen.exe are in your PATH
并确保 putty.exe 和 puttygen.exe 在您的 PATH 中
Then you'll be able to use
然后你就可以使用
vagrant putty
流浪腻子
The above mentioned executables are available from:
上述可执行文件可从以下位置获得:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
回答by Kripa Jayakumar
Either
任何一个
In your
cmd
console type the following:set PATH=%PATH%;C:\Program Files (x86)\Git\bin
在您的
cmd
控制台中键入以下内容:set PATH=%PATH%;C:\Program Files (x86)\Git\bin
OR
或者
Permanently set the path in your system's environment variables:
C:\Program Files (x86)\Git\bin;
在系统的环境变量中永久设置路径:
C:\Program Files (x86)\Git\bin;
回答by Christian Waidner
There is an OpenSSH package for Windows which is basically a stripped down Cygwin. It has an msi-Installer and (after setting your path accordingly) works with "vsagrant ssh":
有一个适用于 Windows 的 OpenSSH 包,它基本上是一个精简的 Cygwin。它有一个 msi-Installer 并且(在相应地设置您的路径后)与“vsagrant ssh”一起使用:
http://sourceforge.net/projects/opensshwindows/?source=directory
http://sourceforge.net/projects/opensshwindows/?source=directory
回答by ThorSummoner
Install Git Bash(Comes with OpenSSH, as well as
grep
,find
,perl
,sed
, etc.;)If you have Vagrant installed, open
appwiz.cpl
(AKA Add/Remove Programs) and Repairthe Vagrant installation. This will make vagrant add itself to your git-bash path.Open Git Bash (Via the start menu)
cd ~/vagrant/mybox
to your vagrant box'es folder andvagrant ssh
安装GIT中击(在OpenSSH配,以及
grep
,find
,perl
,sed
等;)如果您安装了 Vagrant,请打开
appwiz.cpl
(AKA 添加/删除程序)和RepairVagrant 安装。这将使 vagrant 将自己添加到您的 git-bash 路径中。打开 Git Bash(通过开始菜单)
cd ~/vagrant/mybox
到你的 vagrant box'es 文件夹和vagrant ssh
回答by Michael Field
Now I have a much better solution that enables painless Vagrant upgrade. It is based on patched file.
现在我有了一个更好的解决方案,可以实现无痛 Vagrant 升级。它基于补丁文件。
The first line of a vagrantfile should be:
vagrantfile 的第一行应该是:
load "vagrantfile_ssh" if Vagrant::Util::Platform.windows?
And the patched vagrantfile_sshfile (originaly named ssh.rb) should exist in the same directory as vagrantfile. This is both elegant and functional.
并且修补过的vagrantfile_ssh文件(最初名为ssh.rb)应该与vagrantfile存在于同一目录中。这既优雅又实用。
Download the patched vagrantfile_ssh.