Windows Bash(WSL)- sudo:未提供 tty 并且未指定 askpass 程序

15

在按照这篇教程之后,当我尝试以用户或甚至sudo身份运行命令时,我遇到了以下错误:

sudo:no tty present and no askpass program specified

本文中Lurdan的评论指出您需要运行以下命令:

sudo -S <YOUR_COMMAND>
chmod 0666 /dev/tty

chmod 不起作用,但是 sudo -S 起作用了,但是肯定还有其他解决方法吧?

3个回答

29

很傻,看了下面,我看到来自Beorat的解决方案:

为了避免sudo tty问题和其他问题,在运行do-release-upgrade之前,请运行以下命令:

sudo -S apt-mark hold sudo
sudo -S apt-mark hold procps
sudo -S apt-mark hold strace

如果您已经升级,请运行以上命令,然后手动降级到Trusty包:

sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.1_amd64.deb
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/p/procps/procps_3.3.9-1ubuntu2_amd64.deb
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/s/strace/strace_4.8-1ubuntu5_amd64.deb
sudo -S dpkg -i sudo_1.8.9p5-1ubuntu1.1_amd64.deb
sudo -S dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
sudo -S dpkg -i strace_4.8-1ubuntu5_amd64.deb

更多信息在这里:https://github.com/Microsoft/BashOnWindows/issues/482


请注意,当前 sudo 的下载位置已经出现404错误。 - ckittel
3
在sudo软件包的URL中,将1ubuntu1.1_更改为1ubuntu1_以修复404错误。 - srking
1
在安装procps时,我遇到了关于libprocps3的错误。以下命令可以解决该问题: sudo -S dpkg -i libprocps3_3.3.9-1ubuntu2_amd64.deb``` - scott_ri

14

WSL使用lxrun可执行文件在Windows上进行管理:

lxrun -h

Usage:
    /install - Installs the subsystem
        Optional arguments:
            /y - Do not prompt user to accept
    /uninstall - Uninstalls the subsystem
        Optional arguments:
            /full - Perform a full uninstall
            /y - Do not prompt user to accept
    /setdefaultuser - Configures the subsystem user that bash will be launched as. If the user does not exist it will be created.
        Optional arguments:
            username - Supply the username
            /y - If username is supplied, do not prompt to create a password
    /update - Updates the subsystem's package index

鉴于此,您可以使用 lxrun /setdefaultuser root 命令。我认为有必要指出这一点,因为在尝试升级到Xenial后遇到与您相同的问题时,我需要使用该命令。我可以确认,在运行此命令后,再运行 wget / dpkg 命令,我的问题得到了解决。

我使用的命令:

wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.4_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/p/procps/procps_3.3.9-1ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/s/strace/strace_4.8-1ubuntu5_amd64.deb
dpkg -i sudo_1.8.9p5-1ubuntu1.4_amd64.deb
dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
dpkg -i strace_4.8-1ubuntu5_amd64.deb

最后,如果你遇到了 The following packages have unmet dependencies [xxx] but it is not going to be installed 的问题,你可能需要运行 sudo apt-get install -f


1
这个方法很好用。我在执行do-release-upgrade之后遇到了这个问题。一旦我运行了lxrun /setdefaultuser root,我就能够打开一个bash shell并运行visudo来恢复我的用户帐户的sudo权限。之后我回到powershell,运行了lxrun /setdefaultuser <user>,现在回到了我在do-release-upgrade之前的设置状态。 - Jake
@Jake,你能解释一下你是如何给你的用户账户赋予sudo权限的吗?我使用了my_user ALL=(ALL:ALL) ALL - Rahil Wazir
如果您在wget之后按相反的顺序执行此操作,则实际效果会更好,您甚至不必更改默认用户lxrun。 - Rob

1

我通过将/etc/hosts移动到/etc/hosts.bu来解决错误。关闭并重新打开shell后,/etc/hosts会重新创建并添加计算机名称。错误已经消失(对我而言)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接