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]

References πŸ”—οΈŽ