Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a requirement to check that all files which exist in a given directory "must have permission set to 0750 or less." Plus, there'll be a check that all files in a (different) directory should all be owned by a specific user.
I have man'd the ls command, and I can't see a way of listing only files with certain permissions or ownership. I would like to be able to do it with a one-liner. I thought of piping the output of ls -l to awk, substringing the first 10 characters of that and trying to work out what text patterns would violate the audit requirement.
But then I got to thinking that sounded way too complex and that there must be an easier way. Anyone have one?!
But I probably wasn't clear. I don't want to list files which have permissions of exactly 750, which is what I think your first command is giving. I want to list the files which have more or greater permissions than that. IE, 750 is the starting point, not an equality test. And preferably without having to spell out '751, 752, 753...' in a bazillion separate tests.
But I feel some time with the find man page might help, so nice starting point.
Indeed, the man pages are an excellent source of advice, if you know where to look! I've now come up with this:
find /some/directory -perm +0751 -type f | xargs ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
That "+" before the "0751" means it finds permissions greater than or equal to those specified. The gunk at the end of the script is just there so I can see the numeric permissions as well as the rwxrwxrwx version, just for sanity checking. Once I am confident it works, I'll just go back to plain old "xargs ls -l" as in your original reply.
Problem solved, therefore. Find was very definitely the right direction to go in: much appreciated.
By way of follow up, I think the command works fine on Linux, but the -perm parameter doesn't work the same way in Solaris (a -perm +0751 lists only files which have permissions of exactly 751). Is there a way to make a command that works on both?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.