14

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?

3
25

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

sudo nano [filename]
4
  • 9
    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. Apr 18 '17 at 13:32
  • 4
    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' Dec 10 '19 at 22:52
  • 1
    @dGRAMOP cool workaroud. Dec 10 '20 at 13:35
2

If you're the admin, open another terminal

sudo chmod 777 <filename>
<password>

go back to your "nano" terminal save the file. Change permissions back on the filename if you care, they wee most likely 755

1
1

I got your problem and to resolve this error there is a easy way, so basically you need to do nothing but switch from normal user to root user and for that type the command sudo su then enter

Now you have full access, so do whatever you want to do because now you have super user's power.

su means switch user

To create file in nano text editor simply type :- nano [file name] then enter and now can you use all features of nano without any interruption.

There you go, I hope this would be helpful

2
  • The answer "use sudo" was given several times... what is your addition to that? Sep 12 '20 at 10:16
  • I just started learning kali linux and i got the same problem when i was using nano text terminal so i got only one shot to tackle this error.
    – Vishal
    Sep 16 '20 at 8:13

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.