Problems saving changes to /etc/sshd_config

I am trying to setup my mac mini as a secure git server, I'm following this very helpful blog post, http://www.tomdalling.com/blog/software-processes/how-to-set-up-a-secure-git-server-at-home-osx.

Now I get stuck at number 6 when i am trying to save changes I have made to the /etc/sshd_config file. I am logged in as my administrator account and can open the file correctly, when I try to save it I receive the following error:

The document “sshd_config” could not be saved. You don’t have permission.

To view or change permissions, select the item in the Finder and choose File > Get Info.

I have tried to change the permissions using chmod but I can't do this either. I also can't locate it using the finder to be able to change permissions using File > Get Info as suggested in the error message.

Does anyone have any idea how I can resolve this? Please help!


Using sudo on the open command doesn't do anything particularly useful -- the actual program still gets run under the user's regular identity. To solve this, make sure TextEdit isn't running, then do:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit &
open -a "TextEdit" /etc/sshd_config

The first command runs TextEdit as root; the second tells it to open the file. After this, you should be able to edit & save changes. When you're done, be sure to quit TextEdit (or it'll keep editing files as root).

Alternately, use TextWrangler (or its even-more-capable-but-not-free sibling, BBEdit). It handles saving files as root automatically, as well as having easy ways to edit invisible files. I much prefer it for editing config files and the like.

EDIT: Be sure to get the version of TextWrangler from the Bare Bones Software web site, not the version from the Mac App Store -- the App Store version has the save-as-root feature removed to comply with Apple's rules.