0

I have installed VS Code on my Pi. Now I see a problem, I cannot edit and save all the files. Like files that I used to update using nano editor inside the config folders, cannot be edited and saved using VS Code.

For running the command-line editor, we could just run it under Sudo and it was done.

Currently, I am trying to develop a theme for Wordpress and I am stuck as I cannot use VS-Code for this as I cannot save files inside /var/www/html/ folder or sub-folder without using sudo.

How may I do it for VS Code?

Kangkan
  • 398
  • 2
  • 8
  • 22

2 Answers2

1

I'm presuming you are trying to do this as user pi, but the same method applies for anyone. As others have said, running VS code as root probably isn't a great idea. Instead you want to give the VS code user access to the relevant directories.

Get the permissions and ownership set on the directory you want. For example:

> stat /var/www

File: /var/www Size: 4096 Blocks: 8 IO Block: 4096 directory Device: 803h/2051d Inode: 1716748 Links: 4 Access: (0755/drwxr-xr-x) Uid: ( 1028/ foo) Gid: ( 1028/ foo) Access: 2021-02-01 10:08:08.000000000 -0500 Modify: 2021-02-01 10:08:08.000000000 -0500 Change: 2021-02-23 16:41:13.431801967 -0500 Birth: 2018-04-12 12:27:12.113737308 -0400

In this case it is owned by user foo, group foo, permission mode is 0755 meaning anyone can read but only the owner can write. Change this to allow other users in group foo to write:

sudo chmod 775 /var/www

Now, add user pi to the foo group:

sudo usermod -G foo pi

This will be effective when pi next logs in. In theory since it increases access it opens up a vulnerability -- but chances are there was no one in group foo besides user foo, so this is in theory only. To check that:

> grep foo /etc/group
foo:x:1028:pi

The users in the group, except for foo, are shown after the last colon.

An alternative is to change the group ownership of the directory:

> chgrp pi /var/www

Again, since foo still has write access, nothing else will have changed besides granting it to those in group pi -- which is probably just pi.

You can read more about the commands used via (eg.) man chgrp.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
0

This sounds like a "chown" and "chmod" issue with the directory you are trying to "write/save" to. Have you tried this on the directory you want to save into?

Joel Huebner
  • 115
  • 4