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

时间:2022-01-22 23:41:17

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

在关注此tutroial后,我尝试以用户甚至sudo运行命令时出现以下错误:

sudo: no tty present and no askpass program specified

sudo:没有tty存在且没有指定askpass程序

The comments from Lurdan in this article state that you need to run

Lurdan在本文中的评论表明你需要运行

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

chmod doesn't work but sudo -S does, but surely there's another fix?

chmod不起作用,但sudo -S确实如此,但肯定会有另一种解决方法吗?

3 个解决方案

#1


27  

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

#2


14  

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 -f in case you get The following packages have unmet dependencies [xxx] but it is not going to be installed

最后,你可能需要运行sudo apt-get install -f以防你得到以下软件包有未满足的依赖项[xxx]但是它不会被安装

#3


1  

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并添加您的计算机名称。错误消失了(对我而言)

#1


27  

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

#2


14  

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 -f in case you get The following packages have unmet dependencies [xxx] but it is not going to be installed

最后,你可能需要运行sudo apt-get install -f以防你得到以下软件包有未满足的依赖项[xxx]但是它不会被安装

#3


1  

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并添加您的计算机名称。错误消失了(对我而言)