簡體   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