logo
🐧 Linux 命令

Chmod

Chmod Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · Linux 命令🧭 Markdown 速查🏷️ 2 个标签
#chmod#permissions
向下滚动查看内容
返回全部 Cheat Sheets

Getting Started

Syntax
SHELL
滚动查看更多
$ chmod [options] <permissions> <file>

Example

SHELL
滚动查看更多
$ chmod 755 foo.txt
$ chmod +x cheatsheets.py
$ chmod u-x cheatsheets.py
$ chmod u=rwx,g=rx,o= cheatsheets.sh

Change files and directories recursively

SHELL
滚动查看更多
$ chmod -R 755 my_directory

The chmod command stands for "change mode"

Chmod Generator
<widget name="chmod"/>

Chmod Generator allows you to quickly and visually generate permissions in numerical and symbolic.

Common Permissions
CommandsMeaning
400r--------Readable by owner only
500r-x------Avoid Changing
600rw-------Changeable by user
644rw-r--r--Read and change by user
660rw-rw----Changeable by user and group
700rwx------Only user has full access
755rwxr-xr-xOnly changeable by user
775rwxrwxr-xSharing mode for a group
777rwxrwxrwxEverybody can do everything
Explains
SHELL
滚动查看更多
$ ls -l
-rw-r--r--  1 root root 3 Jun 29 15:35 a.log
drwxr-xr-x  2 root root 2 Jun 30 18:06 dir

Permission analysis of "dir"

TEXT
滚动查看更多
d  rwx  r-x  r-x
┬  ─┬─  ─┬─  ─┬─
│   │    │    │
│   │    │    └─ 4. Other|5 (4+0+1)
│   │    └────── 3. Group|5 (4+0+1)
│   └─────────── 2. User |7 (4+2+1)
└─────────────── 1. File Type | directory
Permission Modes
PermissionDescriptionOctalDecimal
---No Permission0000 (0+0+0)
--xExecute0011 (0+0+1)
-w-Write0102 (0+2+0)
-wxExecute and Write0113 (0+2+1)
r--Read1004 (4+0+0)
r-xRead and Execute1015 (4+0+1)
rw-Read and Write1106 (4+2+0)
rwxRead, Write and Execute1117 (4+2+1)

{.show-header}

Objects
Who (abbr.)Meaning
uUser
gGroup
oOthers
aAll, same as ugo

{.show-header}

Permissions
AbbreviationPermissionValue
rRead4
wWrite2
xExecute1
-No permission0

{.show-header}

File Types
AbbreviationFile Type
dDirectory
-Regular file
lSymbolic Link

{.show-header}

Chmod Examples

Operators
SymbolDescription
+Add
-Remove
=Set
chmod 600
SHELL
滚动查看更多
$ chmod 600 example.txt
$ chmod u=rw,g=,o= example.txt
$ chmod a+rwx,u-x,g-rwx,o-rwx example.txt
chmod 664
SHELL
滚动查看更多
$ chmod 664 example.txt
$ chmod u=rw,g=rw,o=r example.txt
$ chmod a+rwx,u-x,g-x,o-wx example.txt
chmod 777
SHELL
滚动查看更多
$ chmod 777 example.txt
$ chmod u=rwx,g=rwx,o=rwx example.txt
$ chmod a=rwx example.txt
Symbolic mode

Deny execute permission to everyone.

SHELL
滚动查看更多
$ chmod a-x chmodExampleFile.txt

Allow read permission to everyone.

SHELL
滚动查看更多
$ chmod a+r chmodExampleFile.txt

Make a file readable and writable by the group and others.

SHELL
滚动查看更多
$ chmod go+rw chmodExampleFile.txt

Make a shell script executable by the user/owner.

SHELL
滚动查看更多
$ chmod u+x chmodExampleScript.sh

Allow everyone to read, write, and execute the file and turn on the set group-ID.

SHELL
滚动查看更多
$ chmod =rwx,g+s chmodExampleScript.sh
Removing Permissions

In order to remove read write permissions given to a file, use the following syntax:

SHELL
滚动查看更多
$ chmod o-rw example.txt

For our file example.txt, we can remove read write permissions using chmod for group by running the following command:

SHELL
滚动查看更多
$ chmod  g-rx example.txt

To remove chmod read write permissions from the group while adding read write permission to public/others, we can use the following command:

SHELL
滚动查看更多
$ chmod g-rx, o+rx example.txt

But, if you wish to remove all permissions for group and others, you can do so using the go= instead:

SHELL
滚动查看更多
$ chmod go= example.txt
Executable
SHELL
滚动查看更多
$ chmod +x ~/example.py
$ chmod u+x ~/example.py
$ chmod a+x ~/example.py
chmod 754
SHELL
滚动查看更多
$ chmod 754 foo.sh
$ chmod u=rwx,g=rx,o=r foo.sh

Chmod Practices

SSH Permissions
SHELL
滚动查看更多
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/id_rsa
$ chmod 600 ~/.ssh/id_rsa.pub
$ chmod 400 /path/to/access_key.pem
Web Permissions
SHELL
滚动查看更多
$ chmod -R 644 /var/www/html/
$ chmod 644 .htaccess
$ chmod 644 robots.txt
$ chmod 755 /var/www/uploads/
$ find /var/www/html -type d -exec chmod 755 {} \;
Batch Change
SHELL
滚动查看更多
$ chmod -R 644 /your_path
$ find /path -type d -exec chmod 755 {} \;
$ find /path -type f -exec chmod 644 {} \;

See: Command Substitution

Also see

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572