I have a file on a ubuntu server which should only be accessible from one user. There are other users on the server with sudo permissions. I am trying to restrict the access of this file despite another user can just sudo to see/modify the contents.

I've looked into visudo which I've disabled chmod and chown commands. So the user cannot change the file permissions. I've looked into an access control list and from my understanding it's it would be able to be bypassed with sudo.

So my question is, how can I restrict the access to a file by one and only one user. Without having the ability to sudo in the bypass the permissions.

  • 1
    Is encrypting the data securely a feasible solution ?
    – Criggie
    Apr 27, 2021 at 11:53

2 Answers 2


The only way to do this is to deny access to sudo for those other users. If you have multiple people with sudo aka admin privileges you can't restrict access to sudo/root and are better off NOT keeping this file on the server. Especially if you don't trust everyone with administrative privileges on the system from not snooping your data.

Permissions to run anything as sudo is essentially equal to having root access but without the root account being unlocked. root has access to everything. You won't be able to stop that access.

Short of removing sudo from those users or adding special sudoers lines to define exactly what commands can be run via sudo by those other sudo-capable users (and nothing else, in this sense 'restricted' admin rights since they can't do just anything with their sudo), you have no options to protect against sudo / root viewing the file.

Other alternatives would be encrypting the file locally on your system BEFORE uploading, such as with gpg encryption or such. In those cases, even if they can access the file, they can't edit or view the contents because they're encrypted, and won't have your decryption codes necessary to read the files, even as root. However that's more complex and a bit outside the scope of the question you asked.


I would start by asking a different question: What privileges do the other users need from sudo? If they only need to be able to do specific things(like restarting the server) and access specific folders, then you can configure sudo to only give them permission to do those specific things as a root. Your file will be safe, and in fact the entire system will have more robust security.

If, on the other hand, the users need sudo for full root access except for this one file, then there's no way restrict their access while still storing the file on that server, so the proper way to solve the issue is to store the file(or at least, a master copy of the file) elsewhere, and only allow the other users to download a temporary copy when they need to view it. The users, after all, have the ability to change anything on the server, including any limitations you try to place on them.

However, all of this is just beating around the bush. If these people can't be trusted, why do they have root access in the first place?

  • This sounds pretty much like the single line I said of "if you don't trust the admins". How is this really different from the answer I stated, which says "remove sudo from those users or restrict what they can actually do with sudo"?
    – Thomas Ward
    Apr 27, 2021 at 13:33
  • 7
    @ThomasWard The conceptual part (the first paragraph) is different, saying to only give sudo users access to what they absolutely need, rather than trying to figure out what access they don't need. The rest is the usual redundancy that happens due to everyone wanting to try and cover all cases.
    – trlkly
    Apr 27, 2021 at 17:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .