Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Sometimes in desperation, to test if my problem is not the permission problem I do:

sudo chmod -R 777 mydir/

In most cases it does not helps, and now I have two problems ;)

Files inside mydir/ had different permissions and owners each, and now I need to restore them to the original state.

Is there any smart way to recursive restore the permissions, except creating a backup copy? E.g.

command_to_save_the_permissions_somewhere mydir/
chmod -R 777 mydir/
command_to_restore_the_permissions_from_somewhere mydir/

BTW, any tips on debugging permission issues?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

There's an easy way to back up and restore permissions amd ownerships of a directory tree using the ACL tools. It works even if you don't have ACLs enabled on the filesystem.

getfacl -R >saved-permissions
setfacl --restore=saved-permissions

Most permission issues will cause a “permission denied” error message to appear somewhere, either on the console or in some log file.

A powerful tool to investigate file access issues is strace. It shows the system calls made by a process. The output can be difficult to understand, but it's relatively easy to see what files the program is trying to access and why it can or cannot find what it wants. Usage examples:

strace -s9999 -o myprogram.strace myprogram  # trace myprogram
strace -s9999 -fF ...                        # also trace subprocesses
strace -s9999 -p12345                        # connect to running process by PID
strace -s9999 -efile ...                     # only show filesystem calls
strace -eaccess,open,stat,lstat              # only show common file access calls
share|improve this answer
add comment

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.