I have some files inside a folder with various formats like .txt, .pem, .csv and .json.
I want only sudo/root to be able access them. I have done

chmod 700


chmod 600

on each of those files. But, I can still print the private key of my .pem files by doing cat on terminal without sudo privileges and open .json files from the file system in "gedit".

What has gone wrong? How do I not let anyone access the contents of those files?

  • please post the output of the command ls -l. – Tejas Lotlikar Nov 15 '20 at 8:04

Suppose your file is named example.txt. Then:

$ sudo chown root: example.txt
$ sudo chmod o-rwx example.txt

should do the job.

If you want an entire directory exampledir to be accessible only to root:

$ sudo chown -R root: exampledir
$ sudo chmod -R o-rwx exampledir
  • How to also undo it? I mean to say, remove those restrictions and make them accessible to not root user too? – Naveen Kumar Nov 15 '20 at 8:16
  • 1
    If your username is student: sudo chown -R student: exampledir – Donald Sebastian Leung Nov 15 '20 at 8:19

Make sure that the owner of the file is root and set the permissions.
Eg filename 'test.txt'
Run the following command

sudo chown root:root test.txt 
sudo chmod 700 test.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.