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
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.)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:
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.
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.