freedombone-utils-passwords 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Password functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. # If this file exists it contains a global password used with
  31. # disk image installs. This simplifies password management for
  32. # deployment at scale
  33. IMAGE_PASSWORD_FILE=/root/login.txt
  34. # Minimum number of characters in a password
  35. MINIMUM_PASSWORD_LENGTH=10
  36. # The default password length used in images
  37. DEFAULT_PASSWORD_LENGTH=20
  38. function enforce_good_passwords {
  39. # because humans are generally bad at choosing passwords
  40. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  41. return
  42. fi
  43. apt-get -yq install libpam-cracklib
  44. sed -i 's/password.*requisite.*pam_cracklib.so.*/password required pam_cracklib.so retry=2 dcredit=-4 ucredit=-1 ocredit=-1 lcredit=0 minlen=10 reject_username/g' /etc/pam.d/common-password
  45. mark_completed $FUNCNAME
  46. }
  47. function create_password {
  48. openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c ${1} ; echo -n ''
  49. }
  50. # NOTE: deliberately no exit 0