sergio_educacionit

user_audit.sh funcion

Apr 30th, 2026
90
0
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Crear lista de usuarios del sistema
  4.  
  5.  
  6. arr_users=( $(cat /etc/passwd | cut -d ":" -f 1) )
  7.  
  8.  
  9.  
  10. valid_shells () {
  11.  
  12. local user
  13. local shell
  14.  
  15. user=$1 # variable local
  16. shell=$(getent passwd $user | cut -d ":" -f 7)
  17.  
  18. # cuando la variable esta vacia se rellena con
  19. # valor predeterminado
  20. #shell=${shell:-noshell}
  21.  
  22. echo $shell
  23.  
  24. grep "$shell" /etc/shells > /dev/null 2>&1 && return 0
  25. return 1
  26.  
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34. for user in ${arr_users[@]};do
  35.  
  36. echo ${user}:
  37. id $user
  38.  
  39.  
  40. uuid=$(getent passwd $user | cut -d ":" -f 3)
  41.  
  42.  
  43.  
  44. # true and true = true
  45. # false and true = false
  46. # true and false = false
  47. # true or false = true
  48. # false or true = true
  49. # false or false = false
  50. #
  51. if [ $uuid -lt 1000 ] && valid_shells $user ;then
  52.  
  53. echo -e "\033[1;31mWARNING\033[0m: special user has shell"
  54. fi
  55.  
  56. echo shell: $(getent passwd $user | cut -d ":" -f 7)
  57.  
  58.  
  59. echo "---"
  60.  
  61. done
  62.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment