繁体   English   中英

在Windows主机上使用Vagrant运行Chef食谱:SSH问题

[英]Running Chef recipes using Vagrant on Windows host: issue with SSH

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

接下来,我要使用Chef在已创建的VM上置备堆栈。 我尝试使用本地目录食谱以及提供食谱的url,但这可能会失败,因为它无法SSH到guest box,从错误中可以看出:

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中启动来宾OS的同一窗口中工作,以便所有脚本都能正常执行?

现在,当我在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访问权限运行所有命令?

这是我设法使SSH工作的方法:

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

从cygwin内设置openssh

添加〜/ .ssh / id_rsa_vagrant

这里下载

修改〜/ .ssh / config

主机本地主机IdentityFile〜/ .ssh / id_rsa_vagrant

修改ssh目录的权限

chmod 600〜/ .ssh / *

一切都应该正常工作。

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

所以这是步骤:

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

批处理文件如下:

@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

@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

@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

@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

@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

@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

@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

@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

@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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM