Advertisement
justin_hanekom

Safe and Secure Bash

Mar 2nd, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.94 KB | None | 0 0
  1. #!/bin/bash -
  2.  
  3. # File: <filename>
  4. # Copyright (c) 2019 Justin Hanekom <justin_hanekom@yahoo.com>
  5.  
  6. # Permission is hereby granted, free of charge, to any person obtaining
  7. # a copy of this software and associated documentation files
  8. # (the "Software"), to deal in the Software without restriction,
  9. # including without limitation the rights to use, copy, modify, merge,
  10. # publish, distribute, sublicense, and/or sell copies of the Software,
  11. # and to permit persons to whom the Software is furnished to do so,
  12. # subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be
  15. # included in all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  
  25. # Setup a safe Bash scripting environment
  26.  
  27. set -o errexit      # Exit immediately if an error occurs
  28. set -o noclobber    # Do not allow files to be overwritten via redirect
  29. set -o nounset      # Do not allow unset variables
  30.  
  31. # Set the exit code of a pipeline to the rightmost non-zero on error
  32. set -o pipefail
  33. #set -o xtrace       # Trace script execution (i.e., debug mode)
  34. # Set the internal field separator to newline or tab, but not space
  35. IFS=$'\n\t'
  36.  
  37. # Setup a secure Bash scripting environment by: setting a secure path;
  38. # clearing all aliases; clearing the command path hash; setting the hard limit
  39. # to 0 to turn off core dumps; and setting a secure umask
  40.  
  41. PATH=$(PATH='/bin:/usr/bin' getconf PATH); export PATH
  42. \unalias -a
  43. hash -r
  44. ulimit -H -c 0 --
  45.  
  46. UMASK=002
  47. umask ${UMASK}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement