正常的chmod是什么?

发布于 2024-07-16 05:16:27 字数 122 浏览 4 评论 0原文

在我的网络服务器上,我的文件权限到处都是,我想将所有内容“重置”回原来的状态。 我不希望任何用户能够进入并删除我的网络服务器上的内容! 我只是希望他们能够查看 php 页面等。

我应该使用什么 chmod?

On my web server, my file permissions are all over the place and I want to 'reset' everything back to how it originally was. I don't want any users to be able to come in and delete things off my web server! I just want them to be able to look at php pages etc.

What chmod should I use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

不如归去 2024-07-23 05:16:27

以下是我收集的摘要:
用法:chmod;

  • chmod 所有文件644
  • chmod 所有.htaccess 文件到644
  • chmod all robots.txt 文件到 644
  • chmod 所有目录711
  • chmod 所有目录 目录列表(.htaccess选项+索引)到755
  • chmod用户可以上传文件的所有目录755(例如:/uploads/)。

说明:

  • 644表示:
    • 6:文件/目录的所有者可以读取写入,但不能执行。 由于文件不可执行,因此您不需要在这里拥有“x”权限(6 表示 r+w。7 表示 r+w+x)。
    • 44:文件/目录所属的(使用ls -l查看组)和其他人( public)能够读取该文件,但不能执行或写入该文件(权限号 4)。
  • 711 表示:
    • 7:文件/目录的所有者可以读取写入执行。 这是目录所需要的! 如果没有“执行”,当您尝试列出目录时,您的权限将被拒绝。
    • 11:文件/目录所属的公共仅具有执行权限。 这适用于您不希望其他人浏览内容但又想让他们访问目录下的选定文件的目录。
  • 755 表示:
    • 7:文件/目录的所有者可以读取写入执行。李>
    • 55:文件/目录所属的公共拥有读取执行权限但不写。 这使用户能够查看目录中的文件,并能够读取这些文件,但不能更改它们。

还有一个交互式在线计算器,您可以使用它来确定要使用的权限:https://chmod-calculator.com/

Here's a summary that I have gathered:
Usage: chmod <number> <filename>

  • chmod all files to 644
  • chmod all .htaccess files to 644
  • chmod all robots.txt files to 644
  • chmod all directories to 711
  • chmod all directories with directory listing (.htaccess Options +Indexes) to 755
  • chmod all directories that users can upload files to, to 755 (ex: /uploads/).

Explanations:

  • 644 means:
    • 6: the owner of the file/directory can read and write, but not execute. Since files are not executable, you don't need to have "x" rights here (6 means r+w. 7 means r+w+x).
    • 44: The group that the file/directory belongs to (see the group by using ls -l) and everyone else (the public) are able to read the file, but not execute or write to it (permission number 4).
  • 711 means:
    • 7: the owner of the file/directory can read, write, and execute. This is needed for directories! Without "execute" when you try to list the directory you'll get permission denied.
    • 11: The group that the file/directory belongs to and the public have execute rights only. This is suitable for directories where you don't want other people browsing through the contents but do want to give them access to selected files further down the directory.
  • 755 means:
    • 7: the owner of the file/directory can read, write, and execute.
    • 55: The group that the file/directory belongs to and the public have read and execute permissions but not write. This allows users to be able to view what files are in a directory, and be able to read those files, but not alter them.

There's also an interactive online calculator you can use to figure out what permissions to use: https://chmod-calculator.com/

哭泣的笑容 2024-07-23 05:16:27

它们应该尽可能受到限制,但不能超过。

通常 0644 是一个不错的选择,它赋予所有者读写权限,但其他人只能读取。 0755 用于目录。 但是,它可能取决于您的特定系统设置。

They should be as restrictive as possible, but no more.

Usually 0644 is a good choice, which gives the owner read and write rights, but everybody else only read. 0755 for directories. But, it can depend on your specific system settings.

等数载,海棠开 2024-07-23 05:16:27

如果您想重置所有内容,请执行此命令并解决后果。 通常 644 对于文件来说是一个很好的权限,而 711 对于目录来说是一个很好的权限。 如果您允许目录列表,则使用 755。

$ find /var/www/html \( -type f -execdir chmod 644 {} \; \) \
                  -o \( -type d -execdir chmod 711 {} \; \)

如果您想要侵入性较小的内容,则只需删除组和“其他”的写入位即可。

$ chmod -R go-w /var/www/html

If you want to reset everything, do this command and sort out the consequences. Usually 644 is a good permission for files and 711 is for directories. If you allow directory listings, then use 755.

$ find /var/www/html \( -type f -execdir chmod 644 {} \; \) \
                  -o \( -type d -execdir chmod 711 {} \; \)

If you want something less invasive, then just remove the write bits for group and "other".

$ chmod -R go-w /var/www/html
别理我 2024-07-23 05:16:27

我认为 644 是文件的标准,755 是目录的标准。

I think 644 is standard for files and 755 for directories.

疯狂的代价 2024-07-23 05:16:27

如果您的网络服务器仅提供网页服务,而不允许通过(例如)匿名 FTP 进行访问,则不正确的文件权限将不允许用户删除文件。

如果其他人可以通过其他方式(例如 SSH)访问您的服务器,请确保没有为您以外的用户设置写入位。 执行:

find . -exec chmod go-w {} \;

该命令将限制执行该命令的所有文件和目录的权限。

If your webserver serves only webpages, without allowing access through (e.g.) anonymous FTP, then incorrect file permissions do not allow users to remove files.

If other people have access to your server through other means (e.g. SSH), then make sure that the write-bit is not set for users other than yourself. Execute:

find . -exec chmod go-w {} \;

This command will restrict the permissions of all files and directories in which it is executed.

少女情怀诗 2024-07-23 05:16:27

无论您使用哪种方法,如果您的 Web 应用程序有可能依赖具有特定权限的文件或目录,请务必进行彻底的测试。 虽然允许过于宽松的权限可能是糟糕的设计,但有时确实会发生这种情况,因此您可能会破坏应用程序。

Whichever approach you use, be sure to do some thorough testing if there is any chance that your web application relies files or dirs having certain permissions. While allowing too permissive permissions is probably bad design, this does happen sometimes, so you might break the application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文