Opening apache conf file with write permissions I'm trying to open the /private/etc/apache2/httpd.conf file to make some changes. I thought I'd be able to open this with the correct permissions from the command line, so I tried:

cd /private/etc/apache2
sudo open -a TextEdit httpd.conf


This opened the file in TextEdit, but TextEdit gave me this message:


  You don't own the file "httpd.conf" and don't have permission to write to it. 
  You can duplicate this document and edit the duplicate. Only the duplicate will include your changes.


Fine. Apparently using open even with sudo opens the app as the user. So I tried this:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit httpd.conf


But I immediately get this popup:


  The document "httpd.conf" could not be opened. You don't have permission.
  To view or change permissions, select the item in the Finder and choose File > Get Info.


This makes TextEdit hang too, so I have to force quit it. 

I also tried to open the file using my Komodo text edit, which is my normal development environment: 

sudo -b /Applications/Komodo\ Edit\ 8.app/Contents/MacOS/komodo httpd.conf


The terminal spits out this strange message:


  2014-09-24 11:48:29.583 komodo[30647:507] * WARNING: Method userSpaceScaleFactor in class NSWindow is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. 


And Komodo opens, but doesn't open the file. How do I edit this file with my program of choice?
The reason these applications can't write to that files is to do with application sandboxing feature of OS X, which you can read about here if you are interested.

One GUI application that can write to these files is TextWrangler which you can download for free here. There is also a version of TextWrangler in the Mac App Store (MAS) but it doesn't have the ability to write to system files by default (MAS guidelines don't allow applications with those abilities), but you can find an update here that will update the MAS version of TextWrangler so that it can.

Alternatively you can use command line tools to edit these files. For example sudo nano https.conf works okay, and nano is relatively user friendly.