在 CentOS7 上无法使用 "Vagrant halt" 命令
Doesn't work "Vagrant halt" command on CentOS7
我已经通过 VirtualBox 和 Vagrant 创建了一个新的 CentOS Linux release 7.2.1511 (Core) box 我也按照正确的步骤创建它
“Vagrant up”和“vagrant ssh”命令工作正常,但是当我尝试“vagrant halt”时出现以下错误:
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
当我通过“vagrant ssh”命令和运行“shutdown -h now”命令进入框时,我被要求输入 vagrant 用户密码:
[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:
它不应该问我,因为我在 sudoers 文件中添加了以下行:
hww_vagrant ALL=(ALL) NOPASSWD: ALL
,我也在 sudoers 文件中评论了以下行:
Defaults requiretty
问题出在这里....当我尝试运行“vagrant halt”失败时,当 vagrant 用户试图关闭盒子时我被要求输入密码。
我认为它应该适用于我的配置,但仍然要求我输入“流浪者”用户关闭盒子的密码...有人知道发生了什么事吗?
谢谢!
基于此post,以下应该可行
使用内容
创建一个文件/etc/polkit-1/rules.d/00-stop-reboot.rules
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;
}
});
您必须在打包器中添加它(如果您使用它来创建盒子)或在打包之前添加它,这样当您 运行 vagrant halt
命令
终于配置成功了。我的 vagrant 用户属于 wheel 组,它导致了错误。
我已经从 wheel 组中删除了我的 vagrant_user 并且它起作用了:
usermod -G "" user_vagrant
谢谢。
我已经通过 VirtualBox 和 Vagrant 创建了一个新的 CentOS Linux release 7.2.1511 (Core) box 我也按照正确的步骤创建它
“Vagrant up”和“vagrant ssh”命令工作正常,但是当我尝试“vagrant halt”时出现以下错误:
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
当我通过“vagrant ssh”命令和运行“shutdown -h now”命令进入框时,我被要求输入 vagrant 用户密码:
[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:
它不应该问我,因为我在 sudoers 文件中添加了以下行:
hww_vagrant ALL=(ALL) NOPASSWD: ALL
,我也在 sudoers 文件中评论了以下行:
Defaults requiretty
问题出在这里....当我尝试运行“vagrant halt”失败时,当 vagrant 用户试图关闭盒子时我被要求输入密码。
我认为它应该适用于我的配置,但仍然要求我输入“流浪者”用户关闭盒子的密码...有人知道发生了什么事吗?
谢谢!
基于此post,以下应该可行
使用内容
创建一个文件/etc/polkit-1/rules.d/00-stop-reboot.rules
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;
}
});
您必须在打包器中添加它(如果您使用它来创建盒子)或在打包之前添加它,这样当您 运行 vagrant halt
命令
终于配置成功了。我的 vagrant 用户属于 wheel 组,它导致了错误。
我已经从 wheel 组中删除了我的 vagrant_user 并且它起作用了:
usermod -G "" user_vagrant
谢谢。