ubuntusshvisual-studio-codevscode-remote

Edit files with VS Code ssh tool that require sudo permissions


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.


Solution

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

    "-t sudo su"
    

    And it works like charm.

    Image of the file