Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to test effective permissions of a file for a specific user?

I normally do this by su user and then accessing the file, but I now want to test this on an user with no shell (i.e. a System user)

share|improve this question

3 Answers 3

up vote 10 down vote accepted

The sudo command can run anything as a particular user with the -u option. Instead of worrying about shells, just try to cat (or execute, whatever) your file as your target user:

$ sudo -u apache cat .ssh/authorized_keys 
cat: .ssh/authorized_keys: Permission denied
share|improve this answer

I've found you can use su -s <shellname> <username> to enter a specific shell as a specific user. You can then test file permissions as usual.

E.g.:

su -s /bin/bash Debian-exim
touch /etc/exim4/exim4.conf.template
share|improve this answer

I found convenient to use in scripts something like

 sudo -u <user> test -r <file-to-test> && ...
share|improve this answer
    
best answer, as you can test for readable (-r), writable (-w) and executable (-x) without actually modifying/creating the file. man test for more details –  Thomas Jul 1 at 18:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.