Checking user access to files in Linux
Published:
| by Julian Knight Reading time ~1 min.
π Posts
| π
Linux
| π
Linux, BASH
How can I know if a user has access to a file or a folder in Linux? Also, what groups is a user a member of? A few things I can never remember how to do.
Add a user to a group ποΈ
sudo usermod -a -G [userName] [groupName]
Check what groups a user is a member of ποΈ
groups [userName]
Check if a user has access to a file or folder ποΈ
sudo -u [userName] ls [path]
# or perhaps
sudo -u [userName] namei [path]
Note that it isnβt always obvious where a blockage may lie in the path. You may need to walk back up the path to find out.
Give a group access to a folder or file ποΈ
sudo chgrp [grpName] [fileOrFolderPath]
# or
sudo chown [userName]:[grpName] [fileOrFolderPath]
Change the level of group access for a folder or file ποΈ
sudo chmod -R g+rwx [fileOrFolderPath]