WSL: sudo doesn't work when "-u" flag is assigned

  • A brief description

sudo command doesn’t when ‘-u’ flag is assigned. For example, sudo -u user ls

  • Expected results

The command should be run

  • Actual results (with terminal output if applicable)

sudo: setresuid() [1000, 1000, 1000] -> [-1, 0, -1]: Operation not permitted

  • Your Windows build number

windows 10 1607 x64

  • Steps / commands required to reproduce the error

    sudo -u user ls

  • Strace of the failing command

execve("/usr/bin/sudo", ["sudo", "-u", "user", "ls"], [/* 16 vars */]) = -1 EPERM (Operation not permitted)
write(2, "strace: exec: Operation not perm"..., 38strace: exec: Operation not permitted
) = 38
exit_group(1)                           = ?
+++ exited with 1 +++
  • Required packages and commands to install

None

See our contributing instructions for assistance.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 7
  • Comments: 18 (8 by maintainers)

Most upvoted comments

Having the same issue trying to access postgres.

> $ sudo -u postgres psql

sudo: setresuid() [1000, 107, 1000] -> [-1, 0, -1]: Operation not permitted

It sounds stupid but try sudo sudo -u

This is fixed in 16251.

Thanks to everyone for the help. I got some time to take a look at this and the issue was our driver not correctly setting the “saved-set” UID or GID on set-user-ID and set-group-ID bit binaries. I have a fix for this and it will be available in a Windows Insider build soon.

Just ran into this myself. Thanks for the workarounds!

Both sudo sudo -i -u postgres and sudo su postgres solutions were effective workarounds for me.

That said, I am now hitting issues as seen in https://github.com/Microsoft/BashOnWindows/issues/61

@ArsalanDotMe – in your previous comment, you want sudo sudo -u postgres psql. (sudo is complaining that you didn’t tell it what command to run 😃 )

That said, it’s definitely true that getting system services like PostgreSQL working within WSL is still a pain. Fortunately, it sounds like it’s being worked on.

Reopening because this is still broken.