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
If it's an executable, use 700 for the permissions.
You can also specify the permissions in a symbolic style:
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).
You can use a program like
gksudo
to prompt you for a password, so if this is a text file you can run:but there is no way I know of to make this happen by default.
Nautilus does possess a scripting feature, so you could install this Nautilus script to open a root nautilus window at the current location, which should then launch the appropriate program with root credentials.
This is pretty simple, so you should be able to modify this to open the file directly using whatever program you want. I don't know any details about the file, so I can't be any more specific.
OK here's how you do this:
It will now show up under right-click -> scripts and use the default gnome application after authenticating.
By default, sudo caches your password for a brief period of time, and so gtksudo does too. To prevent this, run:
and add this to the Defaults line:
This will disable the sudo caching and prompt you for a password every time.