I am not able to save any files on my remote server with VSCode Remote SSH because I am not a root user.
I've followed the official documentation about how to set up ssh with SSH config file but even if my user as sudo privileges, I can't find any options in VSCode to save with sudo.
here is my SSH config file /Users/geoff/.ssh/config
:
Host gcpmain User geoff HostName <IP_ADDRESS> IdentityFile ~/.ssh/gc_rsa
Obviously, when I try to save any files that require sudo I have this expected error message:
Failed to save 'default': Unable to write file (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/etc/nginx/sites-available/default')
Is there any way that I can force VSCode to save as sudo? Thanks a lot for your answers! :)
VS Code Remote SSH SSH, or the secure shell protocol, lets you access a remote computer or virtual machine securely over a network connection. You can connect over SSH into another machine from Visual Studio Code and interact with files and folders anywhere on that remote filesystem.
Add SSH key to your VM#Select Use existing public key in the dropdown for SSH public key source so that you can use the public key you just generated. Take the public key and paste it into your VM setup, by copying the entire contents of the id_ed25519. pub in the SSH public key.
Next time you connect to the remote host, VSCode will use port 5000 , and when you connect via regular ssh from a terminal, you will use port 22 by default, (or specify a custom port via the -p option).
sudo chown -R myuser /path/to/folder
This worked fine for me!
I recommend this VSCode extension: Save as Root in Remote SSH
Install the extension on a window opened with Remote-SSH and use "Save as Root" in the command palette instead of Ctrl+S.
Basically, it reads the contents of the editor and calls the sudo command to overwrite the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With