Edit files with VS Code ssh tool that require sudo permissions

10,166

Solution 1

I actually fixed the VS code extention. If you go to the extention.js and search the running command (it is an array of functions with string output, joined by one empy space), you will find it named l. Just add to the list of the command

"-t sudo su"

And it works like charm.

Check a printscreen

Solution 2

I had exactly the same problem and the only exact answer I found is with:

SSH FS vscode extension

and

adding "sftpSudo": true, to the "sshfs.configs" section in setting.json (look in the extension settings to find it easily).

It will connect the user with sudo automatically, and then we can modify all files on the fly.

Share:
10,166
George T
Author by

George T

Updated on June 04, 2022

Comments

  • George T
    George T almost 2 years

    I am trying to edit some apache configuration files in a server. I would like to use VS code ssh plug in, but I have not found a way to save the configured file, since I am logging into the VM as a user (with sudo permissions) but not root! I get a permission denied error.

    I guess there must be a way to just edit the file from VS code (I also tried winSCP, but no result) and when I save the changes, save them as a sudoer.

    I heard from a friend that when he tried to save the file from VScode, there is a promt to retry as sudo. I do not get that, and unfortunately I do not now any more details, other than he s using Macintosh.

    Suggestions I came across and I do not like:

    1. Change file ownership
    2. Enable root log in

    Suggestions I tried

    1. Tweak with the plug in (Tried to force sudo su as first command, configuring extention.js but there is an error that it writes in an empty pipe)
    2. Using winSCP

    If someone has a suggestion of using another tool, I am happy to hear it.

    Specs

    Server runs Ubuntu 18, apache and my PC windows 10. If any other spec is required I will edit this section.

    TLDR.

    I need a way to edit a file owned by root, having logged in in as a user with root permissions. I would like to do it through a UI interface since I find difficult editing and creating multiple files through nano/vi.