对二进制/可执行文件的写权限:它们有必要吗?

Wik*_*itz 0 linux file-permissions

我想:

echo hello world > /usr/bin/firefox

将在浏览器中显示消息。什么都没有发生。然后我尝试:

echo hello world > /usr/bin/kwrite

查看 kwrite 是否在打开时预先输入了“hello world”。再一次,什么也没发生。然后在尝试执行这两个命令之后:

computer:~$ kwrite
/usr/bin/kwrite: line 1: hello: command not found
computer:~$ firefox
/usr/bin/firefox: line 1: hello: command not found
Run Code Online (Sandbox Code Playgroud)

ls -l /usr/bin/

-rwxr-xr-x 1 root   root     182576 2012-08-21 06:42 apt-ftparchive
-rwxr-xr-x 1 root   root     116996 2012-08-21 06:41 apt-get
-rwxr-xr-x 1 root   root    2151596 2011-10-20 21:45 aptitude
-rwxr-xr-x 1 root   root       1939 2011-10-20 21:45 aptitude-create-state-bundle
-rwxr-xr-x 1 root   root       3007 2011-10-20 21:45 aptitude-run-state-bundle
-rwxr-xr-x 1 root   root       7336 2012-08-21 06:41 apt-key
lrwxrwxrwx 1 root root   20 2012-12-29 10:41 /usr/bin/firefox -> /opt/firefox/firefox
-rwxr-xr-x 1 root root 5476 2010-11-17 04:58 /usr/bin/kwrite
-rwxr-xr-x 1 root   root     181104 2010-02-16 01:40 zip
-rwxr-xr-x 1 root   root       1184 2011-01-21 23:49 zxpdf
Run Code Online (Sandbox Code Playgroud)

/usr/bin我系统上(和其他 bin 文件夹)中的二进制文件至少具有用户对 (?) 的写权限。所以我有效地做的是写入可执行文件“hello world”,尽管它/usr/bin/kwrite是一个二进制 exec 而它/opt/firefox/firefox是一个 shell 脚本

所以很明显,可执行文件很容易出现这种类型的事故。所以我想问一下写权限是否是必要的。我想关闭它,但我想确保我没有在这里遗漏任何东西。

Wel*_*fer 6

首先,您必须echo hello world > /usr/bin/kwrite以 root 身份尝试过,因为所有w或写入位都是

-rwxr-xr-x为用户和组关闭。对于您的第二个问题,只有 root 有权写入

大多数二进制文件,除非它是由普通用户编译和安装的。

你也应该复习你的文件权限符号。这是一个很好的链接