1

I am trying to add a line to my /etc/hosts file but when I go to save it, I get the error "Cannot open file for writing: Permission denied".

The permissions for the file (ls -la /etc/hosts) is as follows:

-rw-r--r--  1 root  wheel  289 Apr 22  2021 /etc/hosts

I've been searching the internet but still can't find my answer. I am running macOS Ventura. How can I edit this file?

9
  • Which version of macOS are you using? Also, it tells you it's a permissions issue. What does ls -la /etc/hosts produce?
    – Allan
    Commented Jan 17, 2023 at 18:55
  • @Allan Ventura 13.1
    – way245
    Commented Jan 17, 2023 at 18:56
  • -rw-r--r-- 1 root wheel 289 Apr 22 2021 /etc/hosts This is what I got!
    – way245
    Commented Jan 17, 2023 at 19:00
  • 1
    That tells you it is readable by root, users in the wheel group, and everyone else. It is only writeable by root. So, to edit it, you need to preface your command with sudo. For example, if using the nano editor: sudo nano /etc/hosts. Enter your password and you'll be able to edit.
    – Allan
    Commented Jan 17, 2023 at 19:03
  • 1
    You have been extremely helpful. Thank you for the warm welcome :)
    – way245
    Commented Jan 17, 2023 at 19:24

1 Answer 1

3

It turns out to be a permissions issue. To edit, the sudo must be used to edit with root permissions:

sudo nano /etc/hosts

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .