I’ve been using VS Code remote SSH to ssh into my droplets and edit files when needed, per this tutorial: https://www.digitalocean.com/community/tutorials/how-to-use-visual-studio-code-for-remote-development-via-the-remote-ssh-plugin
However, up till now I was using a root user. For security purposes, I’m trying to disable root access: https://www.digitalocean.com/community/tutorials/how-to-disable-root-login-on-ubuntu-20-04
But when I ssh with a non-root user, I’m only able to view files with VS Code. If I want to edit/save my changes, I have to use sudo, like so: sudo code filename
, and this throws me an error: sudo: code: command not found
I found a couple of threads discussing this issue, but no resolutions (see below). If anyone has any pointers, I’d appreciate it. I’d really hate having to go back to nano and Vim :)
https://github.com/microsoft/vscode-remote-release/issues/1688 https://github.com/microsoft/vscode/issues/48659
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hello @geochanto
It is a good idea to edit the files with non-root user, as this can also help you to collaborate with other users without the need of giving your root user credentials or sharing ssh-keys.
You can make sure the username is added to the corresponding group (If the files/folders of your site/application are managed by the www-data user/group, then add the user you will use in VSCode to this group).
https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-20-04
I’ll also recommend checking this article on tips and tricks on remote development with Visual Studio Code
https://code.visualstudio.com/docs/remote/troubleshooting
Regards
Hey @geochanto,
The issue should be because you are trying edit files which have root:root ownership. When using a non-root user, you may not have permission to edit certain files or directories. To overcome this issue, you can change the ownership or permissions of the files and directories you need to edit, so your non-root user can modify them without using
sudo
.Here is an example of how you can achieve this using a new group web-admin:
<your_user>
with your non-root username:/var/www/html
directory:Now, you should be able to edit the files in
/var/www/html
using the Remote SSH extension in VS Code without running into permission issues.Remember to replace
/var/www/html
with the path to the files or directories you need to edit. Also, be cautious when changing file permissions, as it can potentially create security vulnerabilities if not handled correctly. Only grant permissions to users who require access to specific files or directories.