Chmod Calculator

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.
Permissions
Owner
Group
Others
Special bits
644Octal
rw-r--r--Symbolic
06444-digit octal

Owner can read and write; group can read; others can read.

A lowercase s or t means the special bit and the execute bit are both set; the uppercase S or T means the special bit is set without execute — which is almost always a mistake worth checking.

Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand Chmod Calculator

在八进制数字(755)、符号记法(rwxr-xr-x)和面向用户、组、其他人的复选框矩阵之间转换 Unix 文件权限。

How it works

权限是九个比特位,分成三组、每组三位,分别对应所有者、所属组和其他所有人。在一组之内,读是 4、写是 2、执行是 1,该位数字就是它们之和——因此 7 是 4+2+1 = rwx,5 是 4+1 = r-x,6 是 4+2 = rw-。这使得 755 恰好是 rwxr-xr-x,644 恰好是 rw-r--r--。前面可选的第四位数字承载特殊位:setuid 是 4,setgid 是 2,粘滞位是 1,这就是为什么 /tmp 是 1777,而共享的组目录常常是 2775。

When to use it

  • 当你知道想要的 rwx 字符串时,算出要传给 `chmod` 的八进制数字,或者在读 `ls -l` 输出时反过来算
  • 修复因组可读而被拒绝的 SSH 密钥——私钥必须是 600,~/.ssh 必须是 700
  • 搭建让新建文件继承所属组的共享目录,这需要 setgid 位(2775),而不是普通的 775
  • 阅读硬编码了权限模式的 Dockerfile、Ansible 任务或部署脚本,并核对它是否真是作者本意

Watch out for

  • 执行位对目录的含义不同。在文件上它意味着「运行它」;在目录上它意味着「进入其中」,因此一个有读权限但没有执行权限的目录,只允许你列出名字,别的什么也做不了——目录设成 644 几乎总是错的。
  • 777 几乎从来不是解决办法。它会让文件对所有人可写,多数 Web 服务器和 SSH 会因此拒绝信任它,而且它掩盖了真正的问题,那通常是归属权而不是权限。
  • 八进制模式是绝对的,符号模式是相对的。`chmod 755` 会一次设定全部九个位,并抹掉你未包含的任何特殊位;而 `chmod u+x` 只加一个位,其余原封不动。
  • 你的 umask 会悄悄做减法。新文件从 666 起算、目录从 777 起算,再减去 umask——因此在常见的 umask 022 下,你得到的是 644 和 755,而不是你可能预期的数字。

Not the right tool for: ACL、扩展属性和 Windows 权限。凡是用 `setfacl`、SELinux 标签或 NTFS ACL 设置的东西,都与这九个比特并存,无法用八进制模式表示。

Frequently Asked Questions

chmod 755 是什么意思?

所有者可读、可写、可执行;组和其他人可读、可执行但不可写。每一位数字是读(4)、写(2)和执行(1)之和,因此 7 = 4+2+1,5 = 4+1。用符号记法表示就是 rwxr-xr-x,这是目录和脚本的常用设置。

644 和 755 有什么区别?

644(rw-r--r--)适用于普通文件:所有者可以编辑,其他所有人只能读取。755(rwxr-xr-x)多了执行位,脚本要运行、目录要能进入,都必须有它。没有执行位的目录无法被进入并列出内容。

权限里的大写 S 或 T 是什么意思?

小写 s 或 t 表示特殊位和执行位都被置位。大写 S 或 T 表示特殊位被置位而执行位没有——这通常是个错误,因为一个无法被执行的 setuid 文件除了在审计中显得可疑之外,什么也做不了。

How to Use Chmod Calculator

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.