Fix rm: cannot remove /etc/resolv.conf: Operation not permitted

It can be quite irritating to get an Operation not permitted when trying to modify or delete the resolv.conf file. It can easily be fixed though.

This error generally occurs because the file has been set as immutable. This can be checked by the following command:

$ sudo lsattr /etc/resolv.conf
----i--------------- /etc/resolv.conf

The i in the above output indicates that it’s immutable attribute is set.

To modify or edit the file, you need to remove the immutable attribute

$ sudo chattr -i /etc/resolv.conf

Verify that the attribute has been removed:

$ sudo lsattr /etc/resolv.conf
-------------------- /etc/resolv.conf

You can now freely modify or edit this file

In case you need to make the file immutable again

$ sudo chattr -i /etc/resolv.conf