17

I use rkhunter and I was wanting to check its logs with:

nano /var/log/rkhunter.log

But nano outputted this error:

Error reading /home/arthur-dent/.nano_history: Permission denied

Press Enter to continue starting nano.

And if I press ENTER I am able to view the file. I have checked the permissions for that file and they are now:

-rw-------   1 root        root           12 May  3 20:26 .nano_history

So I guess that I just change ownership back to me? But as I was literally just using nano, why would the permissions and ownership (possibly, as I do not know what the original ownership was) just suddenly change? Was it because I was just using it with sudo, if so, it is odd as nothing like this has ever happend before and I use sudo with it a lot?


OS Information:

Description:    Ubuntu 15.04
Release:    15.04

Package Information:

nano:
  Installed: 2.2.6-3
  Candidate: 2.2.6-3
  Version table:
 *** 2.2.6-3 0
        500 http://gb.archive.ubuntu.com/ubuntu/ vivid/main amd64 Packages
        100 /var/lib/dpkg/status
5
  • Interesting. Mine says -rw------- 1 xieerqi xieerqi 31 May 3 13:51 .nano_history May 3, 2015 at 19:53
  • /var/log/ needs sudo so the nano command might error out on that.
    – Rinzwind
    May 3, 2015 at 19:55
  • @Rinzwind so you're saying, if one views a file as nano /var/log/somelog, with permissions 600 (and without sudo ), .nano_history changes ownership to root ? I did that just now with atop log, and my .nano_history file is still the same May 3, 2015 at 19:57
  • Thats interesting..if it were a graphical application, this could be caused if you run sudo nano instead of gksudo nano....on a different note, don't parse log files using editors, use tail/less/more -like tools..
    – heemayl
    May 3, 2015 at 20:02
  • @Serg nope. I aint saying that. This happens when you use root with nautilus and change a file as root. And I agree with heemayl What is the idea of using an editor on a log?
    – Rinzwind
    May 3, 2015 at 20:26

2 Answers 2

15

This is possible if .nano_history does not exist and you edit any file as root. Start a search action with Ctrl+W and .nano_history has the wrong ownership.

sudo chown arthur-dent:arthur-dent /home/arthur-dent/.nano_history

Later, the ownership of the file will not be changed.

I've tested:

% ls -l .nano_history
ls: cannot access .nano_history: No such file or directory

% sudo nano ~/tmp/<any_file>

Ctrl+W

Search anything.

Ctrl+X

% ls -l .nano_history
-rw------- 1 root root 6 Mai  3 22:08 .nano_history

% sudo chown aboettger:aboettger .nano_history
% ls -l .nano_history                    
-rw------- 1 aboettger aboettger 6 Mai  3 22:08 .nano_history

% sudo nano ~/tmp/<any_file>

Ctrl+W

Search anything.

Ctrl+X

% ls -l .nano_history  
-rw------- 1 aboettger aboettger 11 Mai  3 22:11 .nano_history
1
  • 1
    Removed my .nano_history and opened sudo nano /var/log/syslog, searched through it, and .nano_history was created as root. So, yeah, this does happen. However, if a file existed previously, it doesn't seem to change ownership to root. I've tried going through syslog again after chmoding my .nano_history, and that one is still owned by me May 3, 2015 at 20:45
9

This can happen when you don't own the .nano_history file that's normally contained inside your home directory. This happened to me when I ran nano for the first time on my Ubuntu install along with sudo. This meant that .nano_history was owned by root and not readable unless sudo was used with nano each time. When it wasn't used, nano complained on startup with 'Permission denied'. Copy and paste this exactly into your terminal to fix the issue:

sudo chown $USER:$(id -gn) $HOME/.nano_history
0

You must log in to answer this question.