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!
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:
sudo groupadd web-admin
<your_user> with your non-root username:sudo usermod -a -G web-admin <your_user>
/var/www/html directory:sudo chown -R :web-admin /var/www/html
sudo chmod -R g+w /var/www/html
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.
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.