0Pricing
Linux Command Line Mastery · บทเรียน

สิทธิ์และเจ้าของไฟล์ด้วย chmod และ chown

เชื่อมโยงการจัดการผู้ใช้กับความปลอดภัยด้วยการเรียนรู้ว่าสิทธิ์ของ Linux ทำงานอย่างไร และตั้งค่าสิทธิ์ด้วย chmod กับ chown ได้อย่างไร

สิทธิ์และเจ้าของไฟล์ด้วย chmod และ chown เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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 ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “สิทธิ์และเจ้าของไฟล์ด้วย chmod และ chown”

เชื่อมโยงการจัดการผู้ใช้กับความปลอดภัยด้วยการเรียนรู้ว่าสิทธิ์ของ Linux ทำงานอย่างไร และตั้งค่าสิทธิ์ด้วย chmod กับ chown ได้อย่างไร คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 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