Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. sudo chgrp -R nobody /whatever
  2.  
  3. mkdir sticky
  4. cd sticky/
  5. touch blub
  6. chmod 4755 blub
  7. ls -al blub
  8.  
  9. chgrp -R myuser .
  10. ls -al blub
  11.  
  12. find /whatever ! -type l -perm -04000 -exec chgrp nobody {} +
  13. -exec chmod u+s {} +
  14. find /whatever ! -type l ! -perm -04000 -exec chgrp nobody {} +
  15.  
  16. chown_preserve_sec() (
  17. newowner=${1?}; shift
  18. for file do
  19. perms=$(stat -Lc %a -- "$file") || continue
  20. cap=$(getfattr -m '^security.capability$' --dump -- "$file") || continue
  21. chown -- "$newowner" "$file" || continue
  22. [ -z "$cap" ] || printf '%sn' "$cap" | setfattr --restore=-
  23. chmod -- "$perms" "$file"
  24. done
  25. )
  26.  
  27. chown_preseve_sec :newgroup file1 file2...
  28.  
  29. # save permissions (and ACLs). Remove the "# owner" and "# group" lines
  30. # to prevent them being restored!
  31. perms=$(getfacl -RPn . | grep -vE '^# (owner|group): ')
  32. # save capabilities
  33. cap=$(getfattr -Rhm '^security.capability$' --dump .)
  34.  
  35. chgrp -RP nobody .
  36.  
  37. # restore permissions, ACLs and capabilities
  38. printf '%sn' "$perms" | setfacl --restore=-
  39. [ -z "$cap" ] || printf '%sn' "$cap" | setfattr -h --restore=-
  40.  
  41. cd /home/me
  42. getfacl -R /whatever > whatever-permissions.org 2> /dev/null
  43.  
  44. # A) change lines starting with # group: root
  45. # to # group: whatineed
  46. sed 's/^# group: root/# group: whatineed/g' whatever-permissions.org > whatever-permissions.new
  47.  
  48. # B) change lines with group::x.y
  49. # to group::xwy
  50. # (where x, y mean: whatever was there before)
  51. sed 's/^group::(.).(.)/group::1w2/g' whatever-permissions.new > whatever-permissions.new
  52.  
  53. cd /
  54. setfacl --restore /home/me/whatever-permissions.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement