mintty / wsltty

Mintty as a terminal for Bash on Ubuntu on Windows / WSL
Other
3.12k stars 104 forks source link

Starting wsltty with elevated privilege #262

Closed suntong closed 4 years ago

suntong commented 4 years ago

How to start wsltty with elevated privilege?

I cannot rename '/home' under wsl:

cd /

$ sudo mv /home home-old
mv: cannot move '/home' to 'home-old': Permission denied

I thought about why I cannot rename '/home' under wsl and the workarounds, and I believe that the reason is, WSL is installed with elevated privilege, while my wsl bash is started with normal privilege. There are just many things that cannot be done because of that, not just moving /home, any files/folders that need elevated privilege to access cannot be altered within wsl bash.

Hence, how to start wsltty with elevated privilege?

Biswa96 commented 4 years ago

Starting wsl.exe or wsltty.exe or wslbridge.exe would not gain root privilege in WSL distribution. Why on earth do you want to rename /home directory?

mintty commented 4 years ago

You could modify the invocation (e.g. in the desktop shortcut) to invoke sudo implicitly, but then you'll have to enter your password initially, unless your distribution would allow to configure sudo to work without password (?). Replace --WSL=distro with --wsl /bin/wslbridge2 -d distro. (wslbridge2 following any mintty parameters) Replace -~ with wslbridge2 parameter --wsldir ~. Append invocation of sudo with shell. Example: C:\Users\towo\AppData\Local\wsltty\bin\mintty.exe --wsl --configdir="C:\Users\towo\AppData\Roaming\wsltty" /bin/wslbridge2 --wsldir ~ /usr/bin/sudo bash -

suntong commented 4 years ago

You could modify the invocation (e.g. in the desktop shortcut) to invoke sudo implicitly, but then you'll have to enter your password initially, unless your distribution would allow to configure sudo to work without password (?).

Oh thanks for your reply @mintty, I guess I wasn't very clear in my OP that,

There are many things that I cannot do even with sudo within wsltty.

What I meant by starting wsltty with elevated privilege is a very Windows-thing, For e.g.,

For opening the Command Prompt as Administrator, i.e., to open the Command Prompt with Administrative Privileges

  1. Click the Start icon and find the cmd (Command Prompt) icon.
  2. Hover the mouse over the cmd program and right-click.
  3. Select "Run as administrator".

This is what I can't do with wsltty icon so far.

mintty commented 4 years ago

Sure you can. Windows offers a generic "Run as administrator" item in the context menu. But why would you want to run the terminal elevated? It doesn't give you anything.

suntong commented 4 years ago

Ah, indeed, there is "Run as administrator" item in the context menu, but not in the pined icon.

image

why would you want to run the terminal elevated? It doesn't give you anything.

It does:

image

I.e., I cannot do even with sudo within normal wsltty, but starting wsltty with elevated privilege is OK.

mintty commented 4 years ago

Not reproduced. Running an un-elevated terminal, then sudo in WSL, gives me all access rights, also in /mnt/c folders.

suntong commented 4 years ago

You machine must have disabled UAC. Here is how to check:

  1. Open powershell or cmd.
  2. Check if it says Administrator in the title

Here is my UAC setting:

image