2

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

接下来,我想使用 Chef 在创建的 VM 上配置堆栈。我尝试使用本地目录食谱以及提供食谱的 url,但这可能会失败,因为它无法 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 主机中启动来宾操作系统的同一窗口内工作,以便所有脚本都能正常执行?

现在,当我在 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

这是因为用户 vagrant 在 box 上没有足够的访问权限,这是我的第二个问题:

2) 如何指示 Vagrant 运行所有具有 sudo 或 su 访问权限的命令?

4

2 回答 2

1

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

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

从 cygwin 中设置 openssh

添加 ~/.ssh/id_rsa_vagrant

这里下载

修改~/.ssh/config

主机 localhost IdentityFile ~/.ssh/id_rsa_vagrant

修改 ssh 目录的权限

chmod 600 ~/.ssh/*

一切都应该正常工作。

于 2013-01-25T09:12:59.123 回答
0

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

所以这里是步骤:

  • 您需要在同一台机器上安装腻子。
  • 您需要在以下批处理脚本中配置 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

于 2012-09-25T21:08:23.723 回答