0Pricing
Linux Command Line Mastery · レッスン

権限と所有者:`chmod`、`chown`

データへのアクセスを安全に制御するため、ファイルの権限と所有者を理解し、管理します。

「権限と所有者:`chmod`、`chown`」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Command Line Mastery学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Command Line Masteryコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Permissions: Who Can Do What?

In Linux, file permissions and ownership are vital for security and managing access to your data. They determine who can read, write, or execute files and directories.

Think of it like a set of rules for your digital property. Without proper permissions, anyone could access or modify your important files!

The Three Pillars: UGO

Linux permissions are categorized into three main types of users, often referred to as UGO:

  • User (Owner): The person who created the file or directory.
  • Group: A collection of users who share specific access rights to the file.
  • Others: Everyone else on the system who is not the owner and not part of the file's group.

Action Types: Read, Write, Execute

For each of the UGO categories, there are three basic types of actions they can perform:

  • Read (r): Allows viewing the file's content or listing a directory's contents.
  • Write (w): Allows modifying or deleting the file, or creating/deleting files within a directory.
  • Execute (x): Allows running a file (if it's a program or script) or entering a directory.

Viewing Permissions with `ls -l`

You can see a file's permissions and ownership using the ls -l command. This command provides a detailed, 'long' listing of files.

The first column shows the file type and permissions in a symbolic format, like -rwxr-xr--.

touch example.txt
ls -l example.txt

`chmod`: Symbolic Mode Basics

The chmod (change mode) command is used to change file permissions. In symbolic mode, you specify who (u, g, o, a) gets what permission (r, w, x) using operators (+, -, =).

  • u: user (owner)
  • g: group
  • o: others
  • a: all (u, g, o)
  • +: add permission
  • -: remove permission
  • =: set permission exactly

`chmod` Symbolic Mode in Action

Let's make our example.txt file executable for the owner, readable for the group, and remove all permissions for others.

Notice how the permissions string changes after each command.

touch example.txt
chmod u+x example.txt
chmod g=r example.txt
chmod o-rwx example.txt
ls -l example.txt

`chmod`: Octal Mode Explained

Octal mode is a numerical way to set permissions. Each permission (r, w, x) is assigned a numerical value:

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

You sum these values for each UGO category. For instance, rwx (4+2+1) is 7, and r-x (4+0+1) is 5.

`chmod` Octal Mode Example

Common octal permissions include:

  • 755: Owner (rwx), Group (rx), Others (rx)
  • 644: Owner (rw), Group (r), Others (r)
  • 600: Owner (rw), Group (-), Others (-)

Let's set example.txt to rw-r--r-- (644).

touch another_file.txt
chmod 644 another_file.txt
ls -l another_file.txt

Changing Ownership with `chown`

The chown (change owner) command is used to change the user and/or group ownership of a file or directory.

Its basic syntax is chown [USER]:[GROUP] [FILE]. You can change just the user, just the group, or both. This command usually requires sudo privileges.

`chown` in Practice

Let's create a file and then change its owner. For this example, we'll assume a user named 'coddy' exists. If not, replace 'coddy' with an existing user on your system.

Note: You'll likely need sudo to execute chown.

touch owned_file.txt
ls -l owned_file.txt
# Assuming 'coddy' is a valid user
sudo chown coddy owned_file.txt
ls -l owned_file.txt

Permissions Check

You have a file named report.txt. You want the owner to have full read, write, and execute permissions. The group should only have read and execute permissions. Others should have no permissions at all.

Which chmod command (octal mode) achieves this?

Recap: Master Your Files!

Great job! You've learned how to manage file permissions and ownership in Linux.

  • ls -l shows permissions in symbolic format.
  • chmod changes permissions using symbolic (u+r) or octal (755) modes.
  • chown changes the owner and/or group of a file, often requiring sudo.

Understanding these commands is crucial for securing your system and collaborating effectively!

よくある質問

「権限と所有者:`chmod`、`chown`」レッスンは無料ですか?

はい。「権限と所有者:`chmod`、`chown`」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。

「権限と所有者:`chmod`、`chown`」で何を学びますか?

データへのアクセスを安全に制御するため、ファイルの権限と所有者を理解し、管理します。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Linux Command Line Masteryを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「権限と所有者:`chmod`、`chown`」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLinux Command Line Masteryレッスンでコードを書いて実行できますか?

はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ファイル内容の表示:`cat`、`less`、`more`
  2. ファイルの検索:`find`と`locate`
  3. 権限と所有者:`chmod`、`chown`
  4. シンボリックリンクを作成して使う
← Linux Command Line Masteryに戻る