WSL/bash-on-windows- sudo broken after release upgrade

9,078

Solution 1

What might help as an alternative to downloading older packages:

  • Log in as Root, via lxrun /setdefaultuser root, or (if you have not upgraded yet) sudo su
  • Set a password for the Root user via passwd

Now you can always switch to root by simply using su root and entering the password you have set, without having to toggle the default user via lxrun.

As an alternative, you can prevent sudo from requiring a password at all, as mentioned in several answers here:

To prevent sudo from asking a password at all, you can add the following line at the end of your /etc/sudoers file (use visudo as root to edit the file)

<username> ALL=(ALL) NOPASSWD: ALL

Be advised, this will cause sudo to no longer ask for a password at all, when executing any Sudo command. If you want to limit the programs that can be used using sudo, add the full path to the binaries (comma separated) instead of the final ALL, eg.:

<username> ALL=(ALL) NOPASSWD: /usr/sbin/cron, /usr/sbin/visudo

Solution 2

Found a solution here:

From cmd:

lxrun /setdefaultuser root

From bash as root:

wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.1_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.1_amd64.deb
dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
dpkg -i strace_4.8-1ubuntu5_amd64.deb

Don't forget to set your non-root default user after your done!

lxrun /setdefaultuser <your user>
Share:
9,078

Related videos on Youtube

Anton Liakhovitch
Author by

Anton Liakhovitch

Updated on September 18, 2022

Comments

  • Anton Liakhovitch
    Anton Liakhovitch over 1 year

    I know I'm not supposed to run do-release-upgrade in WSL, but I did it anyway. The upgrade itself went without errors, but any attempt to run sudo returns:

    sudo: no tty present and no askpass program specified
    

    The output of ls -l /dev as a regular user:

    ls: cannot access 'lxss': Operation not permitted
    ls: random: Invalid argument
    ls: tty: Invalid argument
    ls: tty0: Invalid argument
    total 0
    drwxr-xr-x 2 root     root      0 Aug 15 19:27 block
    lrwxrwxrwx 1 root     root     13 Aug 15 19:27 fd -> /proc/self/fd
    crw------- 1 root     root   0, 0 Aug 15 19:32 kmsg
    c????????? ? ?        ?         ?            ? lxss
    crw-rw-rw- 1 root     root   1, 3 Dec 31  1969 null
    crw-rw-rw- 0 root     tty    5, 2 Aug 15 19:28 ptmx
    drwxr-xr-x 0 root     root      0 Aug 15 19:27 pts
    crw-rw-rw- 1 root     root   1, 8 Aug 15 19:32 random
    lrwxrwxrwx 1 root     root      8 Aug 15 19:27 shm -> /run/shm
    lrwxrwxrwx 1 root     root     15 Aug 15 19:27 stderr -> /proc/self/fd/2
    lrwxrwxrwx 1 root     root     15 Aug 15 19:27 stdin -> /proc/self/fd/0
    lrwxrwxrwx 1 root     root     15 Aug 15 19:27 stdout -> /proc/self/fd/1
    crw--w---- 0 me tty  136, 0 Dec 31  1969 tty
    crw-rw-rw- 1 root     tty    4, 0 Aug 15  2016 tty0
    crw------- 1 me tty    4, 1 Aug 15  2016 tty1
    crw-rw-rw- 1 root     root   1, 9 Aug 15 19:32 urandom
    crw-rw-rw- 1 root     root   0, 0 Aug 15 19:32 zero
    

    Running as root(using lxrun.exe/setdefaultuser) returns the same thing.

    I know I can just reinstall Ubuntu, but I'm still curious as to what might be causing the problem and if there's an easy fix.

    Oh- and date returns Mon Aug 15 19:45:49 DST 2016, like it should.

  • Fabby
    Fabby over 6 years
    Nearly 1 year later: +1, but the above is the best and easiest answer.
  • Anton Liakhovitch
    Anton Liakhovitch over 6 years
    Wow. I forgot that I had even asked this. A year later, I'm using OpenSUSE as my main OS with a Windows installation running in KVM for those occasional use cases. However, this answer is what I would've done now had I still been struggling with that problem.
  • David Lukac
    David Lukac over 5 years
    The mirrors listed above don't work for me, but I've found these working: <pre> wget mirror.hmc.edu/ubuntu/pool/main/s/sudo/… wget mirror.hmc.edu/ubuntu/pool/main/s/strace/… </pre> I couldn't downgrade procps because of missing libprocps3, so I used <pre>mirror.hmc.edu/ubuntu/pool/main/p/procps/…>
  • Ramhound
    Ramhound over 5 years
    This answer suggests a method that would only work for 1709+, which was released a full year after the question was asked and thus is not applicable to this question.
  • Roman
    Roman over 5 years
    My response is addressed to new WSL users first. For now all solution above are already outdated. So I hope my answer will help someone who have more modern build of W10 but have same issue as author of question(with unavailability to run "sudo" and "sudo -s", etc).