Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

TIA

share|improve this question

3 Answers 3

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
1  
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

 
discard

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.