在Windows主机上使用Vagrant运行Chef配方:SSH问题

时间:2012-06-29 20:21:51

标签: windows ssh chef vagrant

我使用Vagrant在Windows主机上创建一个CentOS VM并连接到它,到目前为止一直很好。

接下来我想使用Chef在创建的VM上配置堆栈。我尝试使用本地目录烹饪书以及提供食谱的网址,但这可能会失败,因为它不能ssh到访客框,如错误所示:

SSH authentication failed! This is typically caused by the public/private keypair for the SSH user not being properly set on the guest VM. Please verify that the guest VM is setup with the proper public key, and that the private key path for Vagrant is setup properly as well.

所以我的第一个问题是:

1)如何确保SSH在Windows Host中启动来宾操作系统的同一窗口内工作,以便所有脚本都能正常运行?

现在我在vagrantfile中的下面评论

config.ssh.username = "root"

上面的错误消失了,但我得到了另一个错误:

The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed!

mount -t vboxsf -o uid=id -u vagrant,gid=id -g vagrant v-csr-2 /tmp/vagrant-chef-1/chef-solo-2/roles

这是因为用户流浪者在盒子上没有足够的访问权限,这是我的第二个问题:

2)如何指示Vagrant使用sudo或su access访问所有命令?

2 个答案:

答案 0 :(得分:1)

以下是我设法让SSH工作的方法:

安装cygwin(http://www.cygwin.com/)

在cygwin中设置openssh

添加〜/ .ssh / id_rsa_vagrant

here下载

修改〜/ .ssh / config

主机localhost IdentityFile~ / .ssh / id_rsa_vagrant

修改ssh目录的权限

chmod 600~ / .ssh / *

一切都应该正常。

答案 1 :(得分:0)

我找到了一种从Windows使用批处理文件和相同命令提示符窗口连接到VM的方法。

所以这是步骤:

  • 您需要在同一台机器上安装putty。
  • 您需要在以下批处理脚本中配置putty可执行文件的路径
  • 使用批处理文件连接到您的框

这是批处理文件:

@echo off REM REM This is a replacement for the "vagrant ssh" command on Windows REM (since "vagrant ssh" doesn't actually work on Windows). REM REM PuTTY must be installed. If it is not installed in REM "C:\Program Files (x86)\PuTTY" then set the PUTTY_DIR environment REM to point to the installed location. REM REM As with any vagrant command this should be executed in the directory REM containing the Vagrantfile. REM

setlocal enableextensions

if "%PUTTY_DIR%" == "" ( REM Default location of PuTTY if the Windows installer is used. set "PUTTY_DIR=C:\Program Files (x86)\PuTTY" )

if not exist "%PUTTY_DIR%" ( echo ERROR: PuTTY not found. echo Install PuTTY or check setting of PUTTY_DIR. goto end )

for /F "tokens=1,2" %%A in ('vagrant ssh-config') do ( if "%%A" == "HostName" ( set VagrantHostName=%%B ) if "%%A" == "Port" ( set VagrantPort=%%B ) if "%%A" == "User" ( set VagrantUser=%%B ) if "%%A" == "IdentityFile" ( set IdentityFile=%%B ) )

if "%VagrantHostName%" == "" ( goto end )

if exist %IdentityFile%.ppk ( set "VGPUTTY_OPTIONS=%VGPUTTY_OPTIONS% -i %IdentityFile%.ppk" ) else ( echo. echo TIP: For password-free Vagrant VM login use PuTTYGen to generate echo this file: %IdentityFile%.ppk echo from file: %IdentityFile% echo. )

start "%VagrantHostName%:%VagrantPort%" "%PUTTY_DIR%\PuTTY.exe" %VGPUTTY_OPTIONS% %VagrantUser%@%VagrantHostName% %VagrantPort%

:end