无法访问源文件夹,尽管使用chmod和chown更改权限。

huangapple go评论60阅读模式
英文:

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

问题

这不完全是一个nodejs或npm的问题,而是由Linux设置的权限问题。我以root身份创建了一个nodejs项目(尽管我无法完全回忆所有我执行的操作,这是问题的根源)。然后,我切换到我的帐户,对src文件夹的任何访问都返回权限被拒绝。

我尝试通过接管所有权并设置权限来解决问题。考虑到我的帐户是sam,所属组是sam,我在sam帐户下执行了以下操作:

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

当我使用ls -al列出文件时,显示如下内容:

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

然后我切换到root用户再次列出文件,看到以下内容:

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

甚至在切换到root用户后尝试了以下操作:

su
chown -R sam src
chmod -R 666 src

但是毫无效果。由于这个问题,npm和其他东西完全无法工作。我陷入了两天的困境,有谁能指导我如何解决这个问题。

英文:

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.

答案1

得分: 1

chown -R sam: src,或者sam:sam。你没有改变组。

如果只提供所有者(用户名或数字用户ID),则该用户成为每个给定文件的所有者,文件的组不会更改。如果用户名后跟冒号和组名(或数字组ID),它们之间没有空格,那么文件的组所有权也会更改。如果用户名后跟冒号但没有组名,那么该用户将成为文件的所有者,文件的组将更改为该用户的登录组。

至于权限模式,666 对目录不起作用,因为你需要能够“执行”目录。你可能希望对目录使用755,对非目录文件使用644,除非你有可执行文件(如脚本),那么可以使用744。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月14日 11:07:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定