not able to access the source folder permissions denied despite using chmod and chown

This is not exactly a nodejs or npm problem rather the permissions problem set by linux. I created a nodejs project as as root (which is the source of the problem in my understanding even though i cannot fully recall all the actions I performed). i, then, switched to my account and any access to the src folder returns permission denied.

I tried fixing the issue by taking ownership and setting permisisons. consider my account is sam with the group sam I executed following from sam account

sudo chown -R sam src
sudo chmod -R 666 src

when I do listing using ls -al it shows the following

ls: cannot access 'src/storage': Permission denied
ls: cannot access 'src/.': Permission denied
ls: cannot access 'src/app': Permission denied
ls: cannot access 'src/models.ts': Permission denied
ls: cannot access 'src/..': Permission denied
ls: cannot access 'src/main.ts': Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
d????????? ? ? ? ?            ? app
-????????? ? ? ? ?            ? main.ts
-????????? ? ? ? ?            ? models.ts
d????????? ? ? ? ?            ? storage

I switch to root and do listing again and this is what I see

drw-rw-rw- 4 sam sam 4096 May  9 23:04 .
drwxrwxr-x 9 sam sam 4096 May 10 17:26 ..
drw-rw-rw- 2 sam root    4096 May  9 23:04 app
-rw-rw-rw- 1 sam sam  207 May  9 23:05 main.ts
-rw-rw-rw- 1 sam sam   53 May  9 22:56 models.ts
drw-rw-rw- 2 sam root    4096 May  9 23:02 storage

I even tried the following after switching to the root

su
chown -R sam src
chmod -R 666 src

But to no avail. due to this npm and other things not working at all. It has been two days and I’m stuck with this. Can anyone guide me how can I fix this.

>Solution :

chown -R sam: src, or sam:sam. You’re not changing the group.

If only an owner (a
user name or numeric user ID) is given, that user is made the owner of
each given file, and the files’ group is not changed. If the owner is
followed by a colon and a group name (or numeric group ID), with no
spaces between them, the group ownership of the files is changed as
well. If a colon but no group name follows the user name, that user is
made the owner of the files and the group of the files is changed to
that user’s login group.

And for the mode, 666 won’t work for directories, because you need to be able to "execute" the directory. You probably want 755 on the directories and 644 on non-directory files, unless you have executable files (like scripts) which could be 744.

Leave a Reply