1
votes

I have created a new CentOS Linux release 7.2.1511 (Core) box by VirtualBox and Vagrant also I have followed the proper steps to create it

"Vagrant up" and "vagrant ssh" commands are working properly but when I try to "vagrant halt" I got the following error:

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

shutdown -h now

Stdout from the command:

Stderr from the command:

sudo: no tty present and no askpass program specified

When I go in to the box by "vagrant ssh" command and run the "shutdown -h now" command I have been asked for the vagrant user password:

[hww_vagrant@centos7x64 ~]$ shutdown -h now ==== AUTHENTICATING FOR org.freedesktop.login1.power-off === Authentication is required for powering off the system. Authenticating as: hww_vagrant Password:

It shouldn't ask me as I have add the following row on sudoers file:

hww_vagrant ALL=(ALL) NOPASSWD: ALL

, and also I have commented the following row on sudoers file too:

Defaults requiretty

Here is the problem....as I have been asked for password when vagrant user tries to power off the box when I try to run "vagrant halt" it fails.

I think it should works with my configuration but still asking me the password for powering off the box by "vagrant" user...Does anybody what is happening?

Thanks!

2
when you ssh into the machine and shutdown -h now it can ask you but if you do sudo shutdown -h now it should be ok ? - Frederic Henri
If I type sudo shutdown -h now then I have been asked for password and it works because of my sudoers configuration file (hww_vagrant ALL=(ALL) NOPASSWD: ALL), with this configuration I shouldn't be asked for password and I wouldn't need to type "sudo". What happens when I try to "Vagrant halt" command is vagrant user runs in backgroud "shutdown -h now" command and then the vagrant user is not able to run because it is asked for password when with my configuration it shouldn't happen. - hero_xh

2 Answers

1
votes

based on this post the following should work

create a file /etc/polkit-1/rules.d/00-stop-reboot.rules with the content

polkit.addRule(function(action, subject) {
  if (action.id.indexOf("org.freedesktop.login1.hibernate") == 0) {
    return polkit.Result.AUTH_ADMIN;
  }
});

polkit.addRule(function(action, subject) {
  if (action.id.indexOf("org.freedesktop.login1.power-off") == 0) {
    return polkit.Result.AUTH_ADMIN;
  }
});

polkit.addRule(function(action, subject) {
  if (action.id.indexOf("org.freedesktop.login1.reboot") == 0) {
    return polkit.Result.AUTH_ADMIN;
  }
});

polkit.addRule(function(action, subject) {
  if (action.id.indexOf("org.freedesktop.login1.suspend") == 0) {
    return polkit.Result.AUTH_ADMIN;
  }
});

You will have to add that in packer (if thats what you use for box creation) or just before you package the box so this will be available when you run vagrant halt command

0
votes

Finally, the configuration was ok. My vagrant user belong to wheel group and it was causing the error.

I have removed my vagrant_user from wheel group and it worked:

usermod -G "" user_vagrant

Thanks.