12

When I commit changes on a SVN repository, I always run into the following problem in the terminal in Ubuntu:

Error reading /home/ssylee/.nano_history: Permission denied

Any ideas how to solve it?

2
  • As you can see, there are many ideas on how to solve it, but it kind of depends on why exactly you're experiencing the problem in the first place.
    – David Z
    Commented Jul 4, 2010 at 6:19
  • To reproduce: sudo rm -f ~/.nano_history (remove the file), sudo nano somefile (edit some file as root), ^K sometext (search for some text), ^X (exit), nano somefile (edit some file as you). You'll see Error reading /home/ssylee/.nano_history: Permission denied. nano creates .nano_history to store your search history. The file belongs to root if it is created during a sudo nano session. Commented Sep 28, 2013 at 11:58

6 Answers 6

28

This is usually caused by running sudo nano [file]. This runs the nano process as root, but leaves $HOME set to the regular user's home directory, so if nano creates any files (including the .nano_history file), it will be owned by root and placed in your home directory.

You can verify this by running:

ls -l /home/ssylee/.nano_history

If ls reports that the file is owned by root, then you can be reasonably sure this was the cause. If it is, then the situation can be repaired by running:

sudo chown $USER: ~/.nano_history

or to spell out that command:

sudo chown ssylee: /home/ssylee/.nano_history

A better habit to get into is to use sudoedit or sudo -e instead of sudo nano. This runs the $EDITOR program on a copy of the file being edited, and then atomically replaces the original file when the editor exits (which is very useful when editing system files).

By default, this may launch vi, but you can fix this temporarily by invoking it like so:

EDITOR=nano sudoedit [filename]

You can permanently configure $EDITOR in your .bashrc, or by placing

EDITOR=nano

in /etc/environment.

2
  • 4
    chown $USER: is a shorter way to apply the primary group.
    – Tobu
    Commented Jul 4, 2010 at 13:33
  • 1
    @Tobu, thanks! i didn't know about that trick. I've updated the answer to reflect that. Commented Jul 4, 2010 at 15:42
1

The easiest is to remove the file in question. The next easiest is to make it readable with chmod/chown. The next easiest is to use a different editor.

1

I always use this:
sudo chown -R username:username /home/username

It solves the problem when the permissions are messed up.

1

I would rather do a

ls -la /home/ssylee/.nano_history

first, to see the current permissions. This might help you find out why they went wrong in the first place. If ssylee is the owner of this file, maybe you have a broken default umask?

1

Just change the permissions of .nano_history file as follows:

sudo chown youruser:yourgroup /home/<username>/.nano_history

DONE! The message is gone! =) Really is that simple.

0

The fix requires editing the nano configuration file /etc/nanorc and deleting /home//.nano_history.

First comment out the set historylog parameter of nanorc with this command: sudo nano /etc/nanorc

#set historylog

This will disable the ~/.nano_history file used for saving and reading search /replace strings.

This still leaves the .nano_history file in your user directory. Delete this file as follows:

sudo rm .nano_history

That’s it!

Sources

1
  • This will outright disable history in nano, probably not something users would want to do..
    – Mxx
    Commented Aug 1, 2013 at 16:29

You must log in to answer this question.

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