我使用 Vagrant 在 Windows 主机上创建一个 CentOS VM 并连接到它,到目前为止一切顺利。
接下来,我想使用 Chef 在创建的 VM 上配置堆栈。我尝试使用本地目录 Recipe 并提供 Recipe 的 url,但这可能会失败,因为它无法通过 ssh 连接到 guest 框,如错误所示:
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 主机中启动 guest 操作系统的同一窗口中工作,以便所有脚本都能正常执行?
现在,当我在 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=<code>id -u vagrant</code>,gid=<code>id -g vagrant</code> v-csr-2 /tmp/vagrant-chef-1/chef-solo-2/roles
这是因为用户 vagrant 对 box 没有足够的访问权限,这是我的第二个问题:
2) 如何指示 Vagrant 使用 sudo 或 su 访问权限运行所有命令?
最佳答案
以下是我设法让 SSH 工作的方法:
安装cygwin (http://www.cygwin.com/)
在 cygwin 中设置 openssh
添加 ~/.ssh/id_rsa_vagrant
从here下载
修改~/.ssh/config
主机本地主机 身份文件 ~/.ssh/id_rsa_vagrant
修改ssh目录权限
chmod 600 ~/.ssh/*
一切正常。
关于windows - 在 Windows 主机 : issue with SSH 上使用 Vagrant 运行 Chef Recipe ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11268472/