0Pricing
Linux Command Line Mastery · 课时

使用 chmod 与 chown 管理文件权限和所有权

通过学习 Linux 权限的工作方式以及如何使用 chmod 和 chown 设置权限,连接用户管理与安全知识。

使用 chmod 与 chown 管理文件权限和所有权 是 CoddyKit 上的免费 Linux Command Line Mastery 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Command Line Mastery 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Command Line Mastery 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Permissions Connect Users and Files

Now that you can create users and groups, the next step is controlling what each user can do with files. Linux enforces this through file permissions and ownership.

Reading ls -l Output

ls -l shows a permission string like -rwxr-xr--. The first char is the file type; the next three triples are permissions for owner, group, and others.

ls -l /etc/passwd

The Three Permission Bits

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1

Add them per triple to get an octal digit. rwx = 7, r-x = 5, r-- = 4.

chmod with Octal

chmod 754 file sets owner rwx, group r-x, others r--.

chmod 754 script.sh
ls -l script.sh

chmod with Symbols

You can also add or remove specific bits: u=user, g=group, o=others, a=all.

chmod u+x script.sh
chmod go-w script.sh

Making a Script Executable

A very common task: give a newly written script execute permission so you can run it directly.

chmod +x deploy.sh
./deploy.sh

Changing Ownership with chown

chown user:group file reassigns who owns a file. This ties directly into the user/group management you already learned.

sudo chown alice:developers project.txt

Changing Only the Group

You can change just the group with chgrp or with the :group form of chown.

sudo chown :developers project.txt

Recursive Changes

The -R flag applies changes to a directory and everything inside it. Use carefully.

sudo chown -R alice:developers /srv/app

Default Permissions and umask

New files get default permissions masked by umask. A umask of 022 removes write for group and others, producing 644 files and 755 directories.

umask

A Safe Workflow

When sharing a project directory with a team: set the group, grant group read/write, and keep others restricted.

sudo chown -R :developers /srv/app
sudo chmod -R 770 /srv/app

Quick Check

What octal value represents rwxr-xr--?

Recap

You now control access to files:

  • Permissions split into owner/group/others with r(4)/w(2)/x(1)
  • chmod sets modes via octal or symbols
  • chown/chgrp reassign ownership
  • -R applies recursively; umask sets defaults

常见问题解答

「使用 chmod 与 chown 管理文件权限和所有权」课时是免费的吗?

是的 — 「使用 chmod 与 chown 管理文件权限和所有权」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Command Line Mastery 课程的其余内容,请升级到 CoddyKit PRO。 Linux Command Line Mastery 课程共包含 4 节课。

「使用 chmod 与 chown 管理文件权限和所有权」这节课中我会学到什么?

通过学习 Linux 权限的工作方式以及如何使用 chmod 和 chown 设置权限,连接用户管理与安全知识。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Linux Command Line Mastery 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Linux Command Line Mastery 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「使用 chmod 与 chown 管理文件权限和所有权」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Linux Command Line Mastery 课中编写并运行代码吗?

能。每节 Linux Command Line Mastery 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 用户与组管理:`useradd`、`usermod`、`groupadd`
  2. 网络命令入门:`ping`、`ip`、`netstat`
  3. 安全远程访问:`ssh` 和 `scp`
  4. 使用 chmod 与 chown 管理文件权限和所有权
← 返回 Linux Command Line Mastery