Need better way of handling permissions with nano and sudo mix

Bug #72995 reported by encompass
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
nano (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

After using sudo with nano which is pretty common, I get...
failed to open "/home/jason/.nano_history": Permission denied
I figure this is because the root account when used with sudo makes this file inaccessible for normal use. I use nano with and without sudo and having to press enter for this is annoying. Is there some work around for this?
I could be locked for obvious security reasons. But there has to be a better way.

Revision history for this message
Niklas Spille (niklasspille) wrote :

Same problem here.

I figred out two ways to work around this problem:

1) delete .nano_history (since the file doesn't exist, nano is able to create it using the user's rights. I don't know about any bad consequences this might have?)

2) change .nano_history's permissions (for some strange reason I am unable to reproduce this behavior while writing this...)

It should be possible to do both using a cron job - but there should be a better way?

Revision history for this message
encompass (encompass) wrote :

Thanks for the advice man. I will work with those for now.

Revision history for this message
Jowi (k4p0w3r) wrote :

I can get this error as well.
Each time nano is used with sudo the permission for .nano_history is set to rw for owner. Problem is that the owner is changed from user to root.

Using chown/chmod on .nano_history to revert the owner of the file back to the user is only a temporary fix since the next time nano is used with sudo it will change these permissions back to the "faulty" ones.

I did this to get rid of the error message:
Edit /etc/nanorc and comment out "set historylog". This will of course disable .nano_history all together.

Revision history for this message
Niklas Spille (niklasspille) wrote :

I suppose everything but writing something like "if run with sudo, don't change .nano_history's permissions" into nano is a temporary fix (well, I don't know more about programming than this so I won't be the one who fixes this).

Unsetting historylog would probably be a cleaner way of removing the history file than doing it with a cronjob every other minute...

Revision history for this message
Risto H. Kurppa (risto.kurppa) wrote :

Confirmed here with Feisty. I've usually just changed the permissions of the file but I think it should work out of the box..

r

encompass (encompass)
Changed in nano:
status: Unconfirmed → Confirmed
Revision history for this message
Anders Kaseorg (andersk) wrote :

Using “sudo -e” rather than “sudo nano” gets around this problem by invoking your editor as yourself on a temporary buffer rather than as root. See the description of -e in the sudo(8) manpage.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.