Windows Bash (WSL) - sudo:不存在 tty 且未指定 askpass 程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40046786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:18:54  来源:igfitidea点击:

Windows Bash (WSL) - sudo: no tty present and no askpass program specified

linuxbashubuntuubuntu-16.04windows-subsystem-for-linux

提问by Chris Rogers

After following this tutroialI get the following error when trying to run the commands as user or even sudo:

遵循此教程后,尝试以用户甚至 sudo 身份运行命令时出现以下错误:

sudo: no tty present and no askpass program specified

sudo:不存在 tty 且未指定 askpass 程序

The comments from Lurdanin this article state that you need to run

Lurdan在本文中的评论指出您需要运行

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

chmoddoesn't work but sudo -Sdoes, but surely there's another fix?

chmod不起作用但sudo -S确实如此,但肯定还有其他解决方法吗?

回答by Chris Rogers

So silly, after looking further down I see a solution from Beorat:

太傻了,再往下看后,我看到了Beorat的解决方案:

To avoid the sudo tty issue and others, run these commands just before running do-release-upgrade:

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

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

If you've already upgraded, run the above commands, then manually downgrade to the Trusty packages:

如果您已经升级,请运行上述命令,然后手动降级到 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

More info here: https://github.com/Microsoft/BashOnWindows/issues/482

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

回答by cchamberlain

WSL uses the lxrun executable for management from Windows:

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

lxrun -h

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

Given that, you can use lxrun /setdefaultuser root. Just thought I'd point out this side of it since it was required when I ran into the same issue as you after trying to upgrade to Xenial. I can confirm that running this command, then the wget / dpkg commands my issues were resolved.

鉴于此,您可以使用lxrun /setdefaultuser root. 只是想我会指出它的这一方面,因为当我在尝试升级到 Xenial 后遇到与您相同的问题时需要它。我可以确认运行此命令,然后 wget / dpkg 命令我的问题已解决。

The commands I used:

我使用的命令:

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

Finally, you might need to run sudo apt-get install -fin case you get The following packages have unmet dependencies [xxx] but it is not going to be installed

最后,您可能需要运行sudo apt-get install -f以防万一The following packages have unmet dependencies [xxx] but it is not going to be installed

回答by Freek

I got rid of the error by moving /etc/hosts to /etc/hosts.bu. After closing the shell en opening again, /etc/hosts is recreated and your computer name is added. The error is gone (for me.)

我通过将 /etc/hosts 移动到 /etc/hosts.bu 来消除错误。关闭 shell 再次打开后,会重新创建 /etc/hosts 并添加您的计算机名称。错误消失了(对我来说。)