Wednesday, May 8, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  17] [ 0]  / answers: 1 / hits: 76701  / 3 Years ago, tue, may 25, 2021, 4:08:18

I am trying to use :wq to save a text file I have edited in Vim, but when I enter :wq I get the error



E45: 'readonly' option is set (add ! to override)`  


When I add ! to :wq like :wq!, I get this:



"/etc/dhcp/dhcpd.conf"

"/etc/dhcp/dhcpd.conf" E212: Can't open file for writing


The file I want to edit is dhcpd on the /etc/dhcpd path.



How can I do this?


More From » vim

 Answers
1

You need to open the file using superuser permissions as follows:



sudo vi /etc/dhcp/dhcpd.conf


edit the file by pressing i and then save and exit by pressing Esc and then either :wq or :x or just :w to save.






Thanks to Riking for suggesting sudoedit: you can use sudoedit /path/to/file/filename for editing files owned by root rather than using sudo <editor> /pat/to/file/filename. This is useful for enterprise-level machines or production machines since sudoedit logs to /var/log/auth.log.



If you want to change the default editor for sudoedit, do the following:



sudo update-alternatives --config editor


and then press Return and choose the editor of your choice and again press Return.






See also: A discussion on redit on why sudoedit may be advantegeous


[#25021] Wednesday, May 26, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
memorrappin

Total Points: 325
Total Questions: 122
Total Answers: 100

Location: Armenia
Member since Sat, Sep 12, 2020
4 Years ago
;