51

I'm trying to configure the extension mcrypt in my Ubuntu Server VirtualBox for work in my phpMyAdmin page.

I ran vi /etc/php5/mods-available/mcrypt.ini and then I changed extension=mcrypt.so to extension=/usr/lib/php5/20121212/mcrypt.­so and when I tried to save changes it said this:

E45 readonly option is set (add ! to override)

I think that maybe I made a mistake deleting something before extension=mcrypt.os and I don't know what to do.

karel
  • 110,292
  • 102
  • 269
  • 299
wiry
  • 511
  • 1
  • 4
  • 3
  • 2
    Possible duplicate of [:wq on vim does not save](http://askubuntu.com/questions/471776/wq-on-vim-does-not-save) – David Foerster Jan 08 '17 at 10:33
  • 1
    Try opening the file with ``sudo vi /etc/php5/mods-available/mcrypt.ini`` instead. – Natim Jan 08 '17 at 11:40
  • Possible duplicate of [How do I get permissions to edit system configuration files?](http://askubuntu.com/questions/92379/how-do-i-get-permissions-to-edit-system-configuration-files) – muru Jan 11 '17 at 01:22
  • https://stackoverflow.com/a/28635648 – pzkpfw Sep 06 '19 at 08:58

5 Answers5

36

Probably the user you ran vi /etc/php5/mods-available/mcrypt.ini as did not have write access to the file. vi notices this on file open, and, when you try to save the file, gives you the E45error, and reminds you that you could attempt to override the read-onlyness of the file by appending '!' to the command.

For example, if you edited a file owned by your user, protected 444 (r--r--r--), you would get this message when you did the :wq, but could try to force the write with :wq!. In your case, I suggest doing ls -l /etc/php5/mods-available/mcrypt.ini. To actually edit the file, you could use sudo to temporarily use the power of root, and do sudo vi /etc/php5/mods-available/mcrypt.ini

Zanna
  • 69,223
  • 56
  • 216
  • 327
waltinator
  • 35,099
  • 19
  • 57
  • 93
  • Thank you , i use sudo before vim then i could edit source.list – milad salimi Mar 16 '19 at 08:27
  • Doesn't seem like a permission problem. In my case: ``getfacl file.sh; # file: file.sh # owner: me # group: thegroup user::rwx group::r-x other::r-x`` But I still get the error! As soon as I press "i", this appears ``-- INSERT (paste) -- W10: Warning: Changing a readonly file``, after making some changes, when I try to save I get ``E505: "file.sh" is read-only (add ! to override)``, Same permission also exist for the parent directory: ``# owner: me # group: thegroup user::rwx group::r-x other::r-x ``, this is really weird! And this is happening to any file that I create! – quanta Jun 23 '20 at 15:59
17

You can press Esc , and then U , and then type :q .

You can try opening the file with sudo privilege: sudo vi <file_name>

Purkhalo Alex
  • 319
  • 2
  • 7
13

First come out of the vim editor using: :qa!

Next, use sudo vim filename and later: :wq

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
NadZ
  • 231
  • 2
  • 3
  • 2
    Welcome to [ubuntu.se]! **:-)** This answer is identical to the [highest upvoted answer](https://askubuntu.com/a/635789/344926) – Fabby Jun 25 '19 at 12:23
9

Try the below command

:w !sudo tee %

Explanation, What's happening?

  • :w – write
  • !sudo – call shell sudo command
  • tee – the output of write (:w) command is redirected using tee
  • % – current file name

So, in next Press L to reload.

just this!!!

shgnInc
  • 3,673
  • 4
  • 26
  • 29
  • This is particularly helpful if you have made a ton of changes and do not want to close the file and reopen using `sudo`. – Vishwas M.R Nov 16 '22 at 02:39
1

This happens when the user is trying to write on a file without the right permissions. Login as root using sudo su and now you can do the edit...

Zanna
  • 69,223
  • 56
  • 216
  • 327
peaceman
  • 11
  • 1