'vscode remote-shh: switching user in the file explorer

I have VSCode with the extension remote-ssh installed. I connect to a remote host by username and IdentityFile.

To access certain files on the remote host, I have to switch users using su <user>. But when I switch users, I can only access the file in the terminal and not in the file explorer and therefore I'm unable to use the graphical editor of VSCode to edit my files.



Solution 1:[1]

You can modify your config file like this:

Host remote
....
RemoteCommand su otherUser

according to https://github.com/microsoft/vscode-remote-release/issues/690#issuecomment-993857961

but remember to manually add

"remote.SSH.useLocalServer": true,
"remote.SSH.enableRemoteCommand": true,

to your VSCode settings.json file,

and remember to test the command su otherUser in ssh terminal and make sure it doesn't ask for a password (which will not work with RemoteCommand)

For me, I use RemoteCommand sudo su otherUser and disable sudo password for my ssh user.

Took me a while to search answers and configure, now it works perfectly.

If you have any other questions, go to the issue and read the thread.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pieris