Using the Nano text editor, I'm trying to save and exit a file. I already have the file named.

I click Ctrl+X to exit. And then I click Y because I want to save the file. It asks for file to write, I pressed Enter to use the default name because its already named.

The problem is I get this message.

[Error writing /filename: Permission denied]

What am I doing wrong?


Well, you don't have the rights to write that file. Use

sudo nano [filename]
| improve this answer | |
  • 7
    So there's no way to issue a sudo save while editing the document? i.e. like vi's :wq! ? So if you've spent a while editing a document without realising it's protected, there's no way to save it? Bit of an oversight. – Nathan Hornby Apr 18 '17 at 13:32
  • 1
    You can save to a different filename - hit Ctrl-X, Y, then change to a different filename to write to. That way you can sudo mv it after you edit – dGRAMOP Mar 23 '19 at 18:10
  • This also works if you open a file in Nano and see the message 'file is unwritable' – Chris Halcrow Dec 10 '19 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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