Closed MostHated closed 2 years ago
It's not easy, but it's possible:
SFTP Sudo
to <Default>
(uses sudo <command>
) or a username (uses sudo -u <username> <command>
)SFTP Sudo
will automatically set SFTP Command
to /usr/lib/openssh/sftp-server
if it isn't setSFTP Sudo
to change the location of sftp-server
if it isn't in that default locationSFTP Sudo
is active, the extension tries to detect `Terminal command
defaults to $SHELL
, but your sudo su - user
might work toosu -p -c "cd
pwd; $SHELL"
to keep the environment (-p
) and working directoryTask command
in a similar waysudo
itselfThere'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:
Terminal command
will be run in the login shell of the same user as the Username
field-l
option is to start a login shell, which would reset the working directory, hence the cd
bit-P
option is to start a pseud-terminal, otherwise most shells won't actually properly work (since they require a TTY)$SHELL
being the new user's login shell (which I run)-l
with -w VAR1,VAR2,...
p
if you replace $SHELL
with a hardcoded value instead of getting it from the login shell's environment-l
though, e.g. bash -l
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 entersudo 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
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 entersudo 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