0

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.

user2846870
  • 571
  • 1
  • 8
  • 16
  • Why would you like to avoid sudo on the VM? – tmatilai May 20 '14 at 19:51
  • Because I don't want the default user to have access to files and folders of another user(as sudo users can access everything using the sudo command.) – user2846870 May 21 '14 at 04:43
  • What other users? If you want to install or configure anything in the guest machine you need root access. And if not, why to use Vagrant at all? Just create and spin up the VM directly. – tmatilai May 21 '14 at 06:47
  • I have 2 users, one default user(non-sudo), another privileged user(sudo user).The default user should hav elimited access and should be able to execute "vagrant up" command – user2846870 May 21 '14 at 13:37
  • As I said in my answer, `vagrant up` on the *host* does not require sudo permissions. But the "vagrant" user on the guest VM needs them. – tmatilai May 21 '14 at 13:46
  • The 2 users am referring are users within vagrant guest machine(Ubuntu OS) only... – user2846870 May 22 '14 at 11:50
  • In case it helps anyone, the reason why you can't solve this error by modifying `/etc/sudoers` on the guest and just allowing the non-root user to execute `mkdir` with no password is because Vagrant doesn't just run `sudo mkdir -p /vagrant`, [it runs](https://github.com/hashicorp/vagrant/blob/22db0bb5517d4e3d70781d71e52d4d2891500009/plugins/communicators/ssh/communicator.rb#L537) `sudo -E -H bash -l` by [default](https://www.vagrantup.com/docs/vagrantfile/ssh_settings), and then runs the `mkdir` command in that shell. And you obviously can't allow the `bash` command in sudoers. – gsgx Aug 12 '20 at 00:01

1 Answers1

3

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.

tmatilai
  • 4,071
  • 20
  • 24
  • So how about providing required access alone(by editing /etc/sudoers) to this default user? Then what all privileges should be given to the default user?.. – user2846870 May 21 '14 at 04:59
  • Depends on the Vagrant version, guest OS, your configuration, plugins, etc. You just have to find out (from auth logs) if you really need to go this way. – tmatilai May 21 '14 at 07:04
  • If I am commentting config.vm.network :public_network and disabling shared folder, vagrant up is getting executed without any error. But vagrant halt is giving follwoing error – user2846870 May 22 '14 at 11:52
  • If I am commenting "config.vm.network :public_network" in Vagrantfile and disabling shared folder, vagrant up is getting executed without any error. But vagrant halt is giving error: "Vagrant assumes that this means the command failed! shutdown -h now". – user2846870 May 22 '14 at 11:58
  • Even if am using "config.vm.network :public_network" in Vagrantfile after adding access to non-sudo user "user1" to /etc/network/interfaces and /etc/init.d/networking,vagrant up is giving error: "The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces" – user2846870 May 22 '14 at 12:00