Vagrant Up by Non-Sudo Vagrant User fails

2019-09-08 11:42发布

问题:

I created a new non-sudo user(user1) in vagrant(Ubuntu 12.04 OS), and added the insecure public key to the user1 authorised key file. In vagrant file, added the default user as "user1" :

config.ssh.default.username = "user1"

Now vagrant up is failing with following error message:

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mkdir -p /vagrant

Stdout from the command:

Stderr from the command:

sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts

But if am setting the sudo user for default user, then vagrant up is successful. Can anyone help me with the changes I need to do to enable vagrant up for non-sudo users.

回答1:

Vagrant requires root/sudo permissions on the VM for almost all of it's operations; like configuring the networking, mounting shared folders, running provisioners, etc. So you wouldn't get very useful VM without sudo even if you managed to avoid it.

Note that you only need sudo access on the guest. Vagrant commands itself can (and should) be run as a non-root user on the host.