SchoofsKelvin / vscode-sshfs

Extension for Visual Studio Code: File system provider using SSH
GNU General Public License v3.0
546 stars 36 forks source link

If this is possible, what is the right combination of settings to use to connect via private key, but then work as sudo su - user? #302

Closed MostHated closed 2 years ago

MostHated commented 2 years ago

Hey there, I am trying to determine what are right combination of settings to use to connect via private key, but then work as sudo su - user? When access the system manually, I just connect with the key, then enter sudo su - user and go on about my business, but I have not been able to get that type of thing working with the plugin. Is this possible, or am I going in circles for no reason?

Thanks, -MH

SchoofsKelvin commented 2 years ago

It's not easy, but it's possible:

There's a special edge case that makes it that if SFTP Command starts with sudo, it'll strip the sudo part, e.g. sudo -u user command arg1 becomes command arg1, as the extension tries to auto-detect a potential [sudo] password for user: prompt and auto-answer it with the stored password or prompt you with one, since the SFTP "terminal" isn't visible and doesn't support user interaction. That might interfere with your sudo su, although just prefixing it with a space should make the extension ignore that special procedure.

You might be better off just configuring the extension to login as your target user. You can add the same key to the .ssh/authorized_keys of your target user in case you don't want to have a separate key. You can also use the SSH FS: Open remote SSH terminal or SSH FS: Add as Workspace folder command, select Create instant connection and enter user@configname to connect using an existing config configname but login as user instead, in case all this is just for not having extra configs. And ssh://user@configname/ is a valid URI for e.g. as a workspace folder, that works across restarts.


After a bit of experimenting, this Terminal command seemed to work:

# When the authenticated user has (Ba)sh as login shell
su test-user -lP -c "cd `pwd`;"'$SHELL'
# When the authenticated user has Fish as login shell
su test-user -lP -c "cd "(pwd)";"'$SHELL'

Few notes:

rdsanchezdu commented 1 year ago

Hey there, I am trying to determine what are right combination of settings to use to connect via private key, but then work as sudo su - user? When access the system manually, I just connect with the key, then enter sudo su - user and go on about my business, but I have not been able to get that type of thing working with the plugin. Is this possible, or am I going in circles for no reason?

Thanks, -MH

Hi @MostHated did you find any solution? I can't really understand how to config the extension