更改 Vagrantfile 会导致“vagrant ssh"提示输入密码? [英] Changing Vagrantfile causes "vagrant ssh" to prompt for a password?

查看:92
本文介绍了更改 Vagrantfile 会导致“vagrant ssh"提示输入密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Vagrant 设置环境,但我在使用 vagrant ssh 命令时遇到问题.

I've been playing around with setting up an environment using Vagrant, and I'm having an issue with the vagrant ssh command.

当我更改 Vagrantfile 中已挂载共享文件夹的路径并执行 vagrant reload 时,我无法再 vagrant ssh 而不询问我密码.

When I change the path of the mounted share folder in the Vagrantfile, and do a vagrant reload, I'm no longer able to vagrant ssh without it asking me for a password.

这是我安装共享的原始配置,它有效:

This was my original configuration for a mounted share, which works:

config.vm.synced_folder "./", "/home/vagrant/shared"

这是我试图更改的内容,但在 vagrant reload(要求我输入密码)后不起作用:

This is what I was trying to change to and it doesn't work after vagrant reload (asks me for password):

config.vm.synced_folder "./", "/home/vagrant"

文件中的其他内容保持不变.知道这里发生了什么吗?

Everything else in the file remained unchanged. Any idea what's going on here?

推荐答案

注意这里实际发生的事情.当您共享 /home/vagrant 文件夹时,VM 提供程序(很可能是 VirtualBox)可以控制该文件夹,并且 VirtualBox 会破坏所有权限.您将无法为 .ssh 文件夹设置 0700 perms,也无法为 中的 authorized_keys 文件设置 0600 perms.ssh 文件夹.因此,vagrant ssh 命令将明确要求您输入密码,因为它无法检查 .ssh 文件夹中的公钥.

Take note of what is actually happening here. When you share the /home/vagrant folder the VM Provider (most likely VirtualBox) has control of that folder and the permissions get all mangled by VirtualBox. You won't be able to set the 0700 perms for the .ssh folder nor will you be able to set the 0600 perms for the authorized_keys file inside the .ssh folder. Consequently, the vagrant ssh command will explicitly ask you for the password since it can't check the public key in the .ssh folder.

Makio 关于 /vagrant 是默认共享文件夹的说法是正确的.除了 /home/vagrant 文件夹之外,您几乎可以共享任何您想要的文件夹.我个人知道这一点,因为我遇到了与您相同的问题.通过允许 Vagrant 控制 /home/vagrant 文件夹,相应的权限设置为 vagrant ssh 正常运行.

Makio was right about /vagrant being the default share folder. You can share pretty much any folder you want except for the /home/vagrant folder. I know about this personally because I ran into the very same issue you did. By allowing Vagrant to control the /home/vagrant folder, the permissions get set appropriately for vagrant ssh to function properly.

很高兴它得到了解决,我希望我能更清楚地说明为什么这会给人们带来问题.

Glad it's resolved and I hope I shed a bit more light on exactly why this gives people a problem.

c0p

这篇关于更改 Vagrantfile 会导致“vagrant ssh"提示输入密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆