1

I got an error message today when opening VS code as sudo/root,

"It is recommended not to run Code as 'root'."

THis seems so stupid, Visual Studio code is an IDE, an IDE is used to editing files is it not? Without sudo you wouldn't be able to edit, create, delete, modify, or do anything with any file, so what would the point of the IDE be without sudo? I'm struggling to understand why its a bad idea.

Am I doing something wrong, and if so what should I do? I'm a web developer, so of course I need write and edit permissions to files. Without that, it wouldn't be an IDE, the program would be useless...

I have the files in /var/www/html.

Eliah Kagan
  • 117,780
  • Yes, you are doing something wrong. You shouldn't run VS Code as root. You should almost never run anything as root, with sudo or otherwise. You should fix the permissions of your files, not run tools as root to get around permissions misconfiguration issues. – dobey Nov 19 '17 at 15:06
  • What files are you trying to edit, the location and permissions there may be your issue – George Udosen Nov 19 '17 at 15:20
  • I have the files in /var/www/html – Lee Nelson Nov 19 '17 at 15:33
  • 2
    @dobey I don't think you necessarily mean to say otherwise, but just to be clear: there are numerous cases where it is far better to edit a file as root than to change its permissions. For example, one would not change the permissions on /etc/crontab or /etc/sudoers to edit them. The differences, here, are that (a) running an IDE as root is virtually always a bad idea and (b) there are several ways to set up permissions in /var/www--or simply to configure one's web server to serve content located elsewhere--that are far better than editing the pages one serves to the web as root. – Eliah Kagan Nov 20 '17 at 05:52
  • @EliahKagan Editing individual disparate files is one thing. Editing individual disparate files with a massive IDE is something completely different. For web pages, I'd say it's even better to not edit files in the DocumentRoot, but to edit in some "project" outside, and then sync over via git/rsync/ssh/whatever. SE devs don't edit the site directly on production, or directly on any web server, for example. – dobey Nov 20 '17 at 12:44
  • Oh, and when it is actually necessary to edit individual files as root, it is far better to do so via some means other than running a GUI text editor under sudo, such as using a console editor like vim in a terminal, or over encrypted network connection such as via ssh. – dobey Nov 20 '17 at 12:47
  • @dobey I'm glad to hear you did not actually mean to advise breaking permissions to avoid running commands as root. – Eliah Kagan Nov 20 '17 at 12:53

0 Answers0