Linux file permissions

24 年 11 月 26 日 星期二 (已编辑)
313 字
2 分钟

What are Linux File Permissions?

0_5FgkfJtRbgCQIJuk

Linux file permissions consist of three sets of permissions:

  1. User Permissions: Dictate actions the file's owner can perform
  2. Group Permissions: Define permissions for members of the file's group
  3. Other Permissions: Set Permissions for all other users on the system

Converting Binary to Octal

For instance, the binary permission 'rwxr-xr-x' translates to the octal permission 755, with each permission having a corresponding numeric value.

Common file permission expressions

  • 755: Typical for executables, allowing the owner full permissions while enabling group members and others to read and execute.
  • 644: Common for regular files, granting the owner read and write permissions while restricting others to read-only access.
  • 777: Grants full permissions to everyone on the system, which can pose security risks and should be used cautiously.

Modifying file permissions

The chmod command is used to modify file permissions in Linux. It allows users to set permissions explicitly or modify them incrementally.

  • To set permissions to 755: chmod 755 myfile
  • To add execute permission for all users: chmod +x myfile

Addtionnaly, chmod can be used with symbolic notation for more direct modifications:

  • To add write permission for the group: chmod g+w myfile
  • To remove execute permission for the others: chmod o-x myfile

Decoding File System Information

-rw-r--r--@ 1 lkw staff 2 11 26 20:40 output.txt

  1. Permissions

-rw-r--r--@

- indicates the type of file(e.g., -for a regular file, d for a directory)

@ indicates the file has extended attributes(e.g. Access control lists). Use -l@ or xattr to view these attributes.

  1. Number of Links

1

  • Shows the number of hard links to the file.
  • At least one link exists for every file, pointing to its node. If the file has additional hard links, this number increases.
  1. Owner

lkw

  • The username of the file's owner.
  • The owner has the permissions defined in the first group(rw-).
  1. Group

staff

  • The name of the group that owns the file.
  • Group members have the permissions defined in the second group(r--).
  1. File size

2

  • Indicates the file size in byes.
  • In this case, the file is 2 bytes long.
  1. Last Modified Time

11 26 20:40

  • The timestamp of the last modification:
    • 11
    • 26
    • 20:40
  1. File name

output.txt

文章标题:Linux file permissions

文章作者:Jorthan

文章链接:https://jorthan.com/posts/linux-file-permission[复制]

最后修改时间:


商业转载请联系站长获得授权,非商业转载请注明本文出处及文章链接,您可以自由地在任何媒体以任何形式复制和分发作品,也可以修改和创作,但是分发衍生作品时必须采用相同的许可协议。
本文采用CC BY-NC-SA 4.0进行许可。