Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to edit /etc/hosts using Vi in Cygwin but it's read only. Is there a command similar to sudo? How do I edit a read-only file?


share|improve this question
up vote 2 down vote accepted

Try doing a forced overwrite. Instead of :wq to write and quit, try: :wq! to force write and quit.

share|improve this answer
Didn't work.... – Nope Mar 20 '11 at 17:57
Try using the Windows runas command then? runas /user:Administrator vi /etc/hosts – Majenko Mar 20 '11 at 17:59
Running cygwin as administrator allowed me to edit the file. Thanks for your help – Nope Mar 20 '11 at 18:05
@Nope You should accept the newer answer posted by Philipp if you ever sign on again! – Matthew Sep 30 '14 at 21:06

Opening your cygwin shell as Administrator will grant your user root access. Then the files will no longer be readonly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.