Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure to open/write with sudo? #28

Closed
theodiefenthal opened this issue Jul 20, 2018 · 7 comments
Closed

Configure to open/write with sudo? #28

theodiefenthal opened this issue Jul 20, 2018 · 7 comments
Labels
enhancement New feature or request

Comments

@theodiefenthal
Copy link

Hi there,

I have access to a remote system with a given user (not root).

This user has sudo priviliges, thus I can view/edit any file in an SSH session and I would like to use VS Code SSH FS plugin to edit some configuration files. But sadly, it doesn't allow me to write those config files due to missing permissions.

Would it be possible to include a "sudo" option in configuration which will kind of run any read/write operation with sudo?

@SchoofsKelvin
Copy link
Owner

I'll be looking into this, but it's not planned right now.
Apparently it can be done, although I'll have to look into something mentioned here: mscdex/ssh2#287

@SchoofsKelvin SchoofsKelvin added the enhancement New feature or request label Sep 8, 2018
@ssanthos
Copy link

Would love to have support for this out of the box.

I'm currently working around this by always making a copy of the file I want to edit to a folder where I have write permissions, edit the file in VS Code, and then use a ssh terminal to copy the edited file back using sudo.

@SchoofsKelvin
Copy link
Owner

As an easier workaround, you can use something like this:

chown -R root:sudo .;
chmod -R g+rwX .;

Assuming your user is in the sudo group, which it should be if it can use sudo, all the files in the current directory (and subdirectories) will be owned by root and the sudo group, with read/write permissions added for the group. Basically, anyone with sudo has access to everything in the current directory and below.

I think I found a (theoretical) way of accomplishing this, but I still need to implement and test it.

@SchoofsKelvin
Copy link
Owner

This feature is now added (288f4ad) and published (extension version 1.10.0)

I'll add documentation (#43) for it soon, but here's a summary:

  • There's a new field sftpCommand added for sshfs configurations
  • If the field is absent, the extension will use the sftp subsystem, as it always did
  • If it's present, it'll run the given command instead of starting the given subsystem
  • For most distributions (e.g. Ubuntu), the default is /usr/lib/openssh/sftp-server (sftp subsystem)
  • You can change it to something else, e.g. sudo /usr/lib/openssh/sftp-server

An example configuration could be;

{
  "root": "/",
  "putty": "test",
  "name": "test",
  "sftpCommand": "sudo /usr/lib/openssh/sftp-server"
}

With this configuration, you'd be accessing files as root, or any other user, should you add the right parameter to the sudo command. Mind that creating files will also be in name of the given user, thus the ownership of the new file might be incorrect.

If there are any issues, feel free to post them here or make a new issue.

@prog1407
Copy link

Thanks a lot for the nice extension. I also really need to have this sudo feature but unfortunately didn't manage to make it work for me. When I press connect it asks for password once and then status of configuration becomes orange. I can imagine that it tries to connect and ideally should ask me for sudo password once again but it doesn't

my config

"sshfs.configs": [ { "root": "/home/red", "host": "192.168.100.100", "port": 22, "username": "red", "password": true, "name": "homeserv", "sftpCommand": "sudo /usr/lib/openssh/sftp-server" } ]
I'm running debian 9

@EwanSadie
Copy link

I am running this from Windows 10. I need to "sudo su - nextusername" but this does not work.
I basically want to do the same as I do in WinSCP using scp and I change the shell

@SchoofsKelvin
Copy link
Owner

I'm currently adding better support for sudo and sftpCommand. You can follow issue #104 for progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants