Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 often use nano for quick edits over ssh. If I combine this with sudo though my .nano_history file becomes unreadable for non-sudo editing. I end getting the following warnings:

Error reading /home/user-name/.nano_history: Permission denied

Is there any way of spitting the history file such that I can still access my non-sudo history?


share|improve this question
up vote 2 down vote accepted

By default sudo only raises your privileges but keeps the old environment (not all, but at least $HOME is kept). So it isn't exactly possible to do what you want, without at least messing with bash aliases...

The easiest way to get rid of this problem is simply chown the existing history files to your own user. Then nano will work fine both as you and as root. (History files are only appended to; they're never deleted automatically and so the ownership will stay.)

share|improve this answer

To avoid similar problems with other dotfiles, I'd recommend using sudo to login as the superuser, rather than just grant privileges to your current user:

sudo su -

Note some shops frown on the use of a superuser, preferring RBAC schemes, but based on the way you are using sudo I'm guessing yours isn't one of them.

share|improve this answer
There's sudo -i for that already, why use su? – grawity Jan 11 '10 at 13:20
I thought this was just old habit, but it isn't: "sudo -i" doesn't evaluate any startup scripts (.login etc.) so you will typically end up with a PATH excluding /sbin and /usr/sbin and similar. "sudo su -" gives you exactly what you would get if you had logged in directly as root. – jmtd Jan 18 '10 at 14:11

Try using the -H switch with sudo. That option sets the $HOME environment variable to the home directory of the target user, typically /root. sudo -H nano <file> will use root's .nano_history file instead of your own.

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.