Solved: How to SSH with sudo?

Hi all, hopefully this is the right community for these kind of questions. I'm using VSCodium with the Open Remote - SSH extension to connect to a VM as a non-root sudo user. No problems connecting and opening the files in VSCodium, and I can modify non-sudo files, but I get the following error when trying to modify files that require sudo: Failed to save 'Caddyfile': Unable to write file 'vscode-remote://ssh-remote+hellhole-caddy/etc/caddy/Caddyfile' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/etc/caddy/Caddyfile')

What is the appropriate way to connect to remote SSH files/folders as sudo?

4 points · 7 comments · view on lemmy.world

7 Comments

slazer2au@lemmy.world · 3 pts · 252d (1 reply)

I edit the file in the ssh terminal. Traefik is like that too.

anticonnor@lemmy.world · 1 pts · 252d

I know I can edit the file in terminal, I'm trying to find a way to modify sudo files over SSH in Codium, not just specific to the Caddyfile example.

anticonnor@lemmy.world · 3 pts · 252d

Found the solution! Installed the "Save as Root in Remote - SSH" extension and restarted Codium. I don't see any new Save as Root options added to the GUI after adding the extension, but using F1 to open the command pallet lets me search for and run the Save as Root command there, which prompts for a password then saves as expected.

Here's the git for the Save as Root extension if anyone is interested: https://github.com/yy0931/save-as-root

StopSpazzing@lemmy.world · 2 pts · 252d (1 reply)

Why not check the group (ls -l /etc/caddy/Caddyfile) the file you are trying to edit is owned by and add your non-root user to the same group?

Or am I wrong here?

anticonnor@lemmy.world · 1 pts · 252d

The user I am SSH'ing as ('connor') is in the sudo group, and the files I'm trying to modify over SSH in Chromium are in the root group. I've tried adding 'connor' to the root group, and just to be safe I restarted the SSH service and Codium and reconnected to the file I'm currently trying to modify in the /etc/caddy folder, but still getting the same error message when I attempt to save.

jacksilver@lemmy.world · 2 pts · 252d (1 reply)

Are they files you'll be repeatedly modifying?

Cause you could just connect in the vscodium terminal and edit the file using vim. That way you don't have to leave vscodium, but don't have to configure your setup to modify protected files.

anticonnor@lemmy.world · 2 pts · 252d

Yes, I'll be repeatedly modifying some of these files, and was hoping to use the Codium editor as some of the files will be large and would like to keep the tools available in an IDE.