Linux – Changing file permission in Linux so that only root can see/use it, open dialog box asking for root password when you dont have enough file permission

filesystemslinuxUbuntu

How to change file permission in Linux so that only root user can access/open the file/dir in Linux.

EDIT

Doing

chmod 600 filename + sudo chown root:root filename  

changes it into only root accessible file. But I can see the file content only when I do $ sudo cat file.txt; but when I just click on it, it says file content can't be displayed. So, when I click on it, I want it to show me a dialog box or something, which prompts me to enter root password and then I can open the file. Is this possible ??

How do I change file permission back from root user to normal user A ?

EDIT 2

I can even do

sudo nautilus . 

and then supply root password to open file. But this is all from terminal. I want to open some kind of application/dialog box so that when I click that file/dir as normal user, it will prompt me to enter root password and not just tell me that you dont have proper file permission to open the file. I guess this must be possible, may be with some scripts. Any idea ?

Thanks 🙂

SOLVED here

Best Answer

sudo chown root:root filename
sudo chmod 600 filename

If it's an executable, use 700 for the permissions.

You can also specify the permissions in a symbolic style:

sudo chmod u=rw filename

For information on Nautilus Scripts and Extensions see here and here. See this for information on an extension called nautilus-gksu that adds an "Open as administrator" item to the context menu (plus other extensions).