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]