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?


6 Answers 6


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

sudo nano [filename]
  • 12
    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, 2017 at 13:32
  • 5
    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, 2019 at 18:10
  • 1
    This also works if you open a file in Nano and see the message 'file is unwritable' Dec 10, 2019 at 22:52
  • 2
    @dGRAMOP cool workaroud. Dec 10, 2020 at 13:35

If you're the admin, open another terminal

sudo chmod 777 <filename>

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


I got your problem and to resolve this error there is an easy way. Basically, you need to do nothing but switch from normal user to root user and for that type the command:

sudo su

and then hit Enter. su means "switch user".

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

To create a file in the nano text editor simply type:

nano [file name]

then hit Enter. Now you can use all features of nano without any interruption.

  • The answer "use sudo" was given several times... what is your addition to that? Sep 12, 2020 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, 2020 at 8:13

I had the same problem. Solved it in the following way:

  1. Go to Search, and type bash.
  2. Right-click on bash and run as administrator.

Now it should work normally.


If using Git Bash on Windows, it helps to run the application as an Administrator.

  • How does Windows come into the equation here?? Oct 3, 2023 at 8:28

Most of what has been said works. However, there is an extreme situation. It goes like this:

sudo nano filename

"Username is not in the sudoers file."

What happens if the user doesn't have this privilege? In that case, you can try the following: Open Linux in "Recovery Mode". Then select "root drop to root shell prompt". After entering the root password, type "adduser username sudo"."

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .