I am trying to edit the file /etc/postfix/main.cf
but this applies to any file.
Currently its permission bits are set to -rw-r--r--
I want to open, edit and save this file when operating as a regular user in emacs. However, try as I might, I just can not do it. Here are the options I have tried.
First I tried this method: C-x C -q
This allows me to edit the buffer well enough, but when I try to save the buffer I am presented with: File main.cf is write-protected; try to save anyway? (yes or no)
and when I type yes
I get:
Doing chmod: operation not permitted, /etc/postfix/main.cf
Similarly, if I try M-! chmod u+w main.cf
at any point I get the message:
chmod: changing permissions of 'main.cf': Operation not permitted
Lastly if I try to edit the file in wdired
with wdired-allow-to-change-permissions
I get
chmod 664 '/etc/postfix/main.cf' failed
Emacs is so powerful it seems like there must be a way to do this without using
the /sudo::/filename
trick mentioned here
Additionally, I think there should be a "permissions" tag here in emacs stack overflow.
C-x C-q
, nor can you change the permissions with wdired. You have to switch to root using sudo to edit files you don't own. I use a variant of Burton's answer in the link Aaron gave.main.cf
file, but for other files in/etc/postfix
) is using group permissions. Since I'm in the root group, which is the normal group for those files, you can just set the files you want to edit tog+w
and then edit at your leisure. But only change the permissions on the files you really need lest you accidentally break things.