betus
betus

Reputation: 93

WSL2 doesn't work after using su to change user

I'm using WSL2 with the Remote - WSL extension for Visual Studio Code. If I do code ., Visual Code opens in the specified folder. However, if I change user with su, the same command outputs:

Command 'code' not found, did you mean:
...

Upvotes: 2

Views: 1271

Answers (1)

NotTheDr01ds
NotTheDr01ds

Reputation: 20765

You seem to be running into this issue, where the Remote extension always uses the default user.

While no solution here is ideal, there are (at least) three options, depending on your exact use-case:

  • Temporarily change the default user:

    You'll need to sudo -e /etc/wsl.conf and add:

    [user]
    default=other_username
    

    Then wsl --terminate <distro> (from PowerShell, CMD, or the Start menu), then restart.

  • Use two different WSL instances with different default users in each one.

  • Possibly, give your default user permissions to whatever files you are trying to edit for the other user.

Upvotes: 3

Related Questions