First I know that use vim to write a binary executable program is not recommended. So, I don't want to talk about its rationality here.

I have a binary program, with permission 755(owner is root), so as user root, I expect the fact that I can write to it. The program is not running, with command lsof and fuser, no output return, then I open it with vi, and type :wq to just write and quit, then vi warns me that E45: 'readonly' option is set (add ! to override). The problem is who set the readonly option? The linux kernel?

Then I add a !, which is :wq! now, the program cannot run now, which is expected.

And the same file with the same permission on another machine with the same OS and kernel version. This time, I can write to it with :wq, the magic here is that I can run the program at this machine, though the md5sum gives different results.

The system is RHEL 6.4. vi in fact is vim.

EDIT: add some command output as @ctrl-alt-delor suggested.

[root@localhost x]# uname -r
[root@localhost x]# whoami 
[root@localhost x]# lsof XXX 
[root@localhost x]# fuser XXX 
[root@localhost x]# ls -l XXX 
-rwxr-xr-x. 1 root root 5178556 Apr 19 13:27 XXX
[root@localhost x]# ls -la
total 5080
drwxr-xr-x.  5 root root    4096 Apr 21 19:23 .
drwxr-xr-x. 10 root root    4096 May 18  2018 ..
-rwxr-xr-x.  1 root root 5178556 Apr 19 13:27 XXX
drwxr-xr-x.  5 root root    4096 Apr 18 17:24 blabla
drwxr-xr-x.  2 root root    4096 Apr 15 18:59 blabla2
drwxr-xr-x.  8 root root    4096 Apr 22 10:36 blabla3

EDIT: according to @Wildcard's comment.

[root@localhost x]# getfacl XXX 
# file: XXX
# owner: root
# group: root

[root@localhost x]# lsattr XXX 
-------------e- XXX

EDIT: add SELINUX info

[root@localhost x]# getenforce 
[root@localhost x]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.

[root@localhost x]# ls -Z XXX 
-rwxr-xr-x. root root unconfined_u:object_r:usr_t:s0   XXX

  • Can you edit the question, to show: what user you are, and a directory listing with ls -la before and after. Apr 21, 2019 at 13:19
  • Could there be ACLs in use, or extended attributes such as the “immutable” flag?
    – Wildcard
    Apr 22, 2019 at 6:30
  • 2
    try the -b option of vim ... Apr 22, 2019 at 11:21

1 Answer 1


Rewards should be given to @Murray Jensen.

The short answer is the ~/.vimrc make the difference.

On the machine that I can't save with :wq:

[root@localhost x]# cat ~/.vimrc 
set fileencodings=utf-8,gb18030,ucs-bom,cp936

vim will check utf-8 validity, if illegal byte found, set the readonly option. It won't set the readonly option in binary mode.

After commenting this line, I can save the file with :wq now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.