On a standard Linux system, any user who has unrestricted sudo (i.e. root) privileges can read or write any file on the machine. Unix file‐permissions (chmod/chown/ACLs) only gate ordinary users; “root” can always override them.
So if both alice and bob have full sudo rights, you cannot reliably stop bob from accessing alice’s files. Your options are:
- Revoke or narrow bob’s sudo privileges
- Use encryption so that only alice holds the decryption key
1. Narrow or Remove sudo for bob
If bob doesn’t really need full root, limit him to just the commands he needs:
• Edit /etc/sudoers (via visudo)
• Create a Cmnd_Alias for allowed commands, e.g.
```
Cmnd_Alias SHELLS = /bin/bash, /usr/bin/zsh
Cmnd_Alias NETWORK = /usr/sbin/ifconfig, /usr/bin/ss
bob ALL=(ALL) NOPASSWD: NETWORK
bob ALL=(ALL) SHELLS # or drop this line to remove shell access
```
• Now bob can only run the listed commands via sudo. He can’t spawn arbitrary shells or read arbitrary files.
Pros: no extra software
Cons: needs careful sudoers maintenance; a single overlooked command may let bob “escape” back to a shell
2. Encrypt alice’s Folder
If you need to keep bob as a “full sudoer” but still hide alice’s data, encrypt it. Only alice (with the passphrase/key) can mount/decrypt:
A. eCryptfs (per‐directory or per‐home)
# as alice:
sudo apt update && sudo apt install ecryptfs-utils
# set up a private encrypted directory under ~/Private
ecryptfs-setup-private
# follow prompts to pick a passphrase. It creates ~/Private and ~/Private/.Private
# each login, your ~/Private directory auto‐mounts after you supply your login passphrase.
# bob, even with sudo, can't decrypt that folder without your passphrase.
B. LUKS (block‐level)
- Create an encrypted container file or LUKS‐formatted partition.
- Mount it only when alice supplies the luks passphrase:
# create 1 GB file
dd if=/dev/zero of=~/mycontainer.img bs=1M count=1024
# format it
sudo cryptsetup luksFormat ~/mycontainer.img
# open it
sudo cryptsetup luksOpen ~/mycontainer.img alice_crypt
# make a filesystem
sudo mkfs.ext4 /dev/mapper/alice_crypt
# mount it
mkdir ~/secure
sudo mount /dev/mapper/alice_crypt ~/secure
sudo chown alice:alice ~/secure
- When you’re done,
sudo umount ~/secure && sudo cryptsetup luksClose alice_crypt. Without the passphrase, bob can’t mount or read it.
C. User‐space Encryption Tools
- encfs, gocryptfs, cryfs: Unprivileged, per‐directory encryption
- gpg / age: Manually encrypt individual files or archives
TL;DR
- If bob has full sudo, you cannot block him via normal file‐permissions.
- Either remove/limit his sudo rights, or encrypt alice’s data so only her passphrase unlocks it.
Which approach works best for you? Let me know if you need step‐by‐step instructions on any of the above!