{"id":353772,"date":"2024-09-02T13:27:47","date_gmt":"2024-09-02T13:27:47","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/detectar-cuentas-de-usuario-inactivas-en-linux\/"},"modified":"2024-10-13T19:09:10","modified_gmt":"2024-10-13T19:09:10","slug":"detectar-cuentas-de-usuario-inactivas-en-linux","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/es\/script-hub\/detectar-cuentas-de-usuario-inactivas-en-linux\/","title":{"rendered":"C\u00f3mo detectar las cuentas de usuario inactivas en Linux: gu\u00eda completa del script"},"content":{"rendered":"<p>La gesti\u00f3n eficaz de las cuentas de usuario es una piedra angular de la seguridad inform\u00e1tica. Entre las diversas medidas para mantener un entorno seguro, el control de las cuentas inactivas o no utilizadas es fundamental. Las cuentas de usuario inactivas en Linux pueden ser potenciales puntos de entrada para actividades maliciosas si no se controlan. Para solucionarlo, vamos a explorar un s\u00f3lido script Bash que alerta a los administradores cuando las cuentas de usuario permanecen inactivas durante un n\u00famero determinado de d\u00edas.<\/p>\n<h2>Background<\/h2>\n<p>Las cuentas de usuario inactivas en Linux plantean riesgos importantes en cualquier infraestructura inform\u00e1tica. Pueden aprovecharse para obtener accesos no autorizados, lo que podr\u00eda dar lugar a una violaci\u00f3n de los datos. <a href=\"https:\/\/www.ninjaone.com\/es\/que-es-un-msp\/\" target=\"_blank\" rel=\"noopener\">Los proveedores de servicios gestionados (MSP)<\/a> y los profesionales de TI necesitan herramientas eficaces para realizar el seguimiento y la gesti\u00f3n de estas cuentas. Este script sirve como una soluci\u00f3n poderosa, ofreciendo alertas automatizadas para cuentas de usuario inactivas en <a href=\"https:\/\/www.ninjaone.com\/blog\/linux-filesystems\/\" target=\"_blank\" rel=\"noopener\">Linux<\/a>, mejorando la postura general de seguridad.<\/p>\n<h2>El script para detectar las cuentas de usuario inactivas en Linux<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/usr\/bin\/env bash\r\n#\r\n# Description: Alerts when there is an inactive\/unused account that has not logged in for the specified number of days.\r\n#\r\n# Preset Parameter: --daysInactive \"90\"\r\n#   Alert if account has been inactive for x days.\r\n#\r\n# Preset Parameter: --showDisabled\r\n#   Includes disabled accounts in alert and report.\r\n#\r\n# Preset Parameter: --multilineField \"ReplaceMeWithNameOfYourMultilineField\"\r\n#   Name of an optional multiline custom field to save the results to.\r\n#\r\n# Preset Parameter: --wysiwygField \"ReplaceMeWithNameOfYourWYSIWYGField\"\r\n#   Name of an optional WYSIWYG custom field to save the results to.\r\n#\r\n# Preset Parameter: --help\r\n#   Displays some help text.\r\n#\r\n# Release Notes: Initial Release\r\n# By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n# Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n# Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n# Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n# Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n# Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n# Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n# EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#\r\n\r\n# These are all our preset parameter defaults. You can set these = to something if you would prefer the script defaults to a certain parameter value.\r\n_arg_daysInactive=\r\n_arg_showDisabled=\"off\"\r\n_arg_multilineField=\r\n_arg_wysiwygField=\r\n\r\n# Help text function for when invalid input is encountered\r\nprint_help() {\r\n  printf '\\n\\n%s\\n\\n' 'Usage: --daysInactive|-d &lt;arg&gt; [--multilineField|-m &lt;arg&gt;] [--wysiwygField|-w &lt;arg&gt;] [--showDisabled] [--help|-h]'\r\n  printf '%s\\n' 'Preset Parameter: --daysInactive \"90\"'\r\n  printf '\\t%s\\n' \"Alert if account has been inactive for x days.\"\r\n  printf '%s\\n' 'Preset Parameter: --showDisabled'\r\n  printf '\\t%s\\n' \"Includes disabled accounts in alert and report.\"\r\n  printf '%s\\n' 'Preset Parameter: --multilineField \"ReplaceMeWithNameOfYourMultilineField\"'\r\n  printf '\\t%s\\n' \"Name of an optional multiline custom field to save the results to.\"\r\n  printf '%s\\n' 'Preset Parameter: --wysiwygField \"ReplaceMeWithNameOfYourWYSIWYGField\"'\r\n  printf '\\t%s\\n' \"Name of an optional WYSIWYG custom field to save the results to.\"\r\n  printf '\\n%s\\n' 'Preset Parameter: --help'\r\n  printf '\\t%s\\n' \"Displays this help menu.\"\r\n}\r\n\r\n# Determines whether or not help text is necessary and routes the output to stderr\r\ndie() {\r\n  local _ret=\"${2:-1}\"\r\n  echo \"$1\" &gt;&amp;2\r\n  test \"${_PRINT_HELP:-no}\" = yes &amp;&amp; print_help &gt;&amp;2\r\n  exit \"${_ret}\"\r\n}\r\n\r\n# Converts a string input into an HTML table format.\r\nconvertToHTMLTable() {\r\n  local _arg_delimiter=\" \"\r\n  local _arg_inputObject\r\n\r\n  # Process command-line arguments for the function.\r\n  while test $# -gt 0; do\r\n    _key=\"$1\"\r\n    case \"$_key\" in\r\n    --delimiter | -d)\r\n      test $# -lt 2 &amp;&amp; echo \"[Error] Missing value for the required argument\" &gt;&amp;2 &amp;&amp; return 1\r\n      _arg_delimiter=$2\r\n      shift\r\n      ;;\r\n    --*)\r\n      echo \"[Error] Got an unexpected argument\" &gt;&amp;2\r\n      return 1\r\n      ;;\r\n    *)\r\n      _arg_inputObject=$1\r\n      ;;\r\n    esac\r\n    shift\r\n  done\r\n\r\n  # Handles missing input by checking stdin or returning an error.\r\n  if [[ -z $_arg_inputObject ]]; then\r\n    if [ -p \/dev\/stdin ]; then\r\n      _arg_inputObject=$(cat)\r\n    else\r\n      echo \"[Error] Missing input object to convert to table\" &gt;&amp;2\r\n      return 1\r\n    fi\r\n  fi\r\n\r\n  local htmlTable=\"&lt;table&gt;\\n\"\r\n  htmlTable+=$(printf '%b' \"$_arg_inputObject\" | head -n1 | awk -F \"$_arg_delimiter\" '{\r\n    printf \"&lt;tr&gt;\"\r\n    for (i=1; i&lt;=NF; i+=1)\r\n      { printf \"&lt;th&gt;\"$i\"&lt;\/th&gt;\" }\r\n    printf \"&lt;\/tr&gt;\"\r\n    }')\r\n  htmlTable+=\"\\n\"\r\n  htmlTable+=$(printf '%b' \"$_arg_inputObject\" | tail -n +2 | awk -F \"$_arg_delimiter\" '{\r\n    printf \"&lt;tr&gt;\"\r\n    for (i=1; i&lt;=NF; i+=1)\r\n      { printf \"&lt;td&gt;\"$i\"&lt;\/td&gt;\" }\r\n    print \"&lt;\/tr&gt;\"\r\n    }')\r\n  htmlTable+=\"\\n&lt;\/table&gt;\"\r\n\r\n  printf '%b' \"$htmlTable\" '\\n'\r\n}\r\n\r\n# Parses command-line arguments and sets script variables accordingly.\r\nparse_commandline() {\r\n  while test $# -gt 0; do\r\n    _key=\"$1\"\r\n    case \"$_key\" in\r\n    --daysInactive | --daysinactive | --days | -d)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n      _arg_daysInactive=$2\r\n      shift\r\n      ;;\r\n    --daysInactive=*)\r\n      _arg_daysInactive=\"${_key##--daysInactive=}\"\r\n      ;;\r\n    --multilineField | --multilinefield | --multiline | -m)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n      _arg_multilineField=$2\r\n      shift\r\n      ;;\r\n    --multilineField=*)\r\n      _arg_multilineField=\"${_key##--multilineField=}\"\r\n      ;;\r\n    --wysiwygField | --wysiwygfield | --wysiwyg | -w)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n      _arg_wysiwygField=$2\r\n      shift\r\n      ;;\r\n    --wysiwygField=*)\r\n      _arg_wysiwygField=\"${_key##--wysiwygField=}\"\r\n      ;;\r\n    --showDisabled | --showdisabled)\r\n      _arg_showDisabled=\"on\"\r\n      ;;\r\n    --help | -h)\r\n      _PRINT_HELP=yes die 0\r\n      ;;\r\n    *)\r\n      _PRINT_HELP=yes die \"FATAL ERROR: Got an unexpected argument '$1'\" 1\r\n      ;;\r\n    esac\r\n    shift\r\n  done\r\n}\r\n\r\n# Parses the command-line arguments passed to the script.\r\nparse_commandline \"$@\"\r\n\r\n# If dynamic script variables are used replace the commandline arguments with them.\r\nif [[ -n $daysInactive ]]; then\r\n  _arg_daysInactive=\"$daysInactive\"\r\nfi\r\n\r\nif [[ -n $includeDisabled &amp;&amp; $includeDisabled == \"true\" ]]; then\r\n  _arg_showDisabled=\"on\"\r\nfi\r\n\r\nif [[ -n $multilineCustomFieldName ]]; then\r\n  _arg_multilineField=\"$multilineCustomFieldName\"\r\nfi\r\n\r\nif [[ -n $wysiwygCustomFieldName ]]; then\r\n  _arg_wysiwygField=\"$wysiwygCustomFieldName\"\r\nfi\r\n\r\n# Check if _arg_daysInactive contains any non-digit characters or is less than zero.\r\n# If any of these conditions are true, display the help text and terminate with an error.\r\nif [[ -z $_arg_daysInactive || $_arg_daysInactive =~ [^0-9]+ || $_arg_daysInactive -lt 0 ]]; then\r\n  _PRINT_HELP=yes die \"FATAL ERROR: Days Inactive of '$_arg_daysInactive' is invalid! Days Inactive must be a positive number.\" 1\r\nfi\r\n\r\n# Check if both _arg_multilineField and _arg_wysiwygField are set and not empty.\r\nif [[ -n \"$_arg_multilineField\" &amp;&amp; -n \"$_arg_wysiwygField\" ]]; then\r\n  # Convert both field names to uppercase to check for equality.\r\n  multiline=$(echo \"$_arg_multilineField\" | tr '[:lower:]' '[:upper:]')\r\n  wysiwyg=$(echo \"$_arg_wysiwygField\" | tr '[:lower:]' '[:upper:]')\r\n\r\n  # If the converted names are the same, it means both fields cannot be identical.\r\n  # If they are, terminate the script with an error.\r\n  if [[ \"$multiline\" == \"$wysiwyg\" ]]; then\r\n    _PRINT_HELP=no die 'FATAL ERROR: Multline Field and WYSIWYG Field cannot be the same name. https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/articles\/360060920631-Custom-Fields-Configuration-Device-Role-Fields'\r\n  fi\r\nfi\r\n\r\n# Retrieves the list of user accounts with UniqueIDs greater than 499 (typically these are all not service accounts) from the local user directory.\r\nuserAccounts=$(cut -d \":\" -f1,3 \/etc\/passwd | grep -v \"nobody\" | awk -F ':' '$2 &gt;= 1000 {print $1}')\r\n\r\n# Sets up a header string for the table that will display user account information.\r\nheader=$(printf '%s' \"Username\" ';' \"Password Last Set\" ';' \"Last Logon\" ';' \"Enabled\")\r\n\r\n# Initializes an empty string to store information about relevant user accounts.\r\nrelevantAccounts=\r\n\r\n# Iterates over each user account retrieved earlier.\r\nfor userAccount in $userAccounts; do\r\n  # Extracts the last login information for that user, filtering out unnecessary lines and formatting.\r\n  lastLogin=$(last -RF1 \"$userAccount\" | grep -v \"wtmp\" | grep \"\\S\" | tr -s \" \" | cut -f3-7 -d \" \")\r\n\r\n  # Converts the last login date to seconds since the epoch, for easier date comparison.\r\n  if [[ -n $lastLogin ]]; then\r\n    lastLogin=$(date -d \"$lastLogin\" +\"%s\")\r\n  fi\r\n\r\n  # Calculates the cutoff date in seconds since the epoch for inactivity comparison, based on the days inactive argument.\r\n  if [[ $_arg_daysInactive -gt 0 ]]; then\r\n    cutoffDate=$(date -d \"${_arg_daysInactive} days ago\" +\"%s\")\r\n  fi\r\n\r\n  # Retrieves the timestamp when the password was last set for the user account and converts it to a readable format.\r\n  passwordLastSet=$(passwd -S \"$userAccount\" | cut -f3 -d \" \")\r\n\r\n  # Checks if the user account is part of the group that defines disabled accounts, setting the 'enabled' variable accordingly.\r\n  unlockedaccount=$(passwd -S \"$userAccount\" | cut -f2 -d \" \" | grep -v \"L\")\r\n  nologin=$(grep \"$userAccount\" \/etc\/passwd | cut -d \":\" -f7 | grep \"nologin\")\r\n  if [[ -n $unlockedaccount &amp;&amp; -z $nologin ]]; then\r\n    enabled=\"true\"\r\n  else\r\n    enabled=\"false\"\r\n  fi\r\n\r\n  # Checks if the account is inactive based on the last login date and cutoff date or if the account should be included regardless of its active status.\r\n  if [[ $_arg_daysInactive == \"0\" || -z \"$lastLogin\" || $lastLogin -le $cutoffDate ]]; then\r\n    # Formats the last login date or sets it to \"Never\" if the user has never logged in.\r\n    if [[ -n $lastLogin ]]; then\r\n      lastLogin=$(date -d \"@$lastLogin\")\r\n    else\r\n      lastLogin=\"Never\"\r\n    fi\r\n\r\n    # Skips adding disabled accounts to the output if they should not be shown.\r\n    if [[ $_arg_showDisabled == \"off\" &amp;&amp; $enabled == \"false\" ]]; then\r\n      continue\r\n    fi\r\n\r\n    # Appends the account information to the 'relevantAccounts' string if it meets the criteria.\r\n    relevantAccounts+=$(printf '%s' '\\n' \"$userAccount\" ';' \"$passwordLastSet\" ';' \"$lastLogin\" ';' \"$enabled\")\r\n    foundInactiveAccounts=\"true\"\r\n  fi\r\ndone\r\n\r\n# Checks if there are any inactive accounts found.\r\nif [[ $foundInactiveAccounts == \"true\" ]]; then\r\n  # Formats a nice table for easier viewing\r\n  tableView=\"$header\"\r\n  tableView+=$(printf '%s' '\\n' \"--------\" ';' \"-----------------\" ';' \"----------\" ';' \"-------\")\r\n  tableView+=\"$relevantAccounts\"\r\n  tableView=$(printf '%b' \"$tableView\" | column -s ';' -t)\r\n\r\n  # Output to the activity log\r\n  echo \"\"\r\n  echo 'WARNING: Inactive accounts detected!'\r\n  echo \"\"\r\n  printf '%b' \"$tableView\"\r\n  echo \"\"\r\nelse\r\n  # If no inactive accounts were found, outputs a simple message.\r\n  echo \"No inactive accounts detected.\"\r\nfi\r\n\r\n# Checks if there is a multiline custom field set and if any inactive accounts have been found.\r\nif [[ -n $_arg_multilineField &amp;&amp; $foundInactiveAccounts == \"true\" ]]; then\r\n  echo \"\"\r\n  echo \"Attempting to set Custom Field '$_arg_multilineField'...\"\r\n\r\n  # Formats the relevantAccounts data for the multiline custom field.\r\n  multilineValue=$(printf '%b' \"$relevantAccounts\" | grep \"\\S\" | awk -F \";\" '{ \r\n      print \"Username: \"$1\r\n      print \"Password Last Set: \"$2\r\n      print \"Last Logon: \"$3\r\n      print \"Enabled: \"$4 \r\n      print \"\"\r\n  }')\r\n\r\n  # Tries to set the multiline custom field using ninjarmm-cli and captures the output.\r\n  if ! output=$(printf '%b' \"$multilineValue\" | \/opt\/NinjaRMMAgent\/programdata\/ninjarmm-cli set --stdin \"$_arg_multilineField\" 2&gt;&amp;1); then\r\n    echo \"[Error] $output\" &gt;&amp;2\r\n    EXITCODE=1\r\n  else\r\n    echo \"Successfully set Custom Field '$_arg_multilineField'!\"\r\n  fi\r\nfi\r\n\r\n# Checks if there is a WYSIWYG custom field set and if any inactive accounts have been found.\r\nif [[ -n $_arg_wysiwygField &amp;&amp; $foundInactiveAccounts == \"true\" ]]; then\r\n  echo \"\"\r\n  echo \"Attempting to set Custom Field '$_arg_wysiwygField'...\"\r\n\r\n  # Initializes an HTML formatted string with headers and account details.\r\n  htmlObject=\"$header\"\r\n  htmlObject+=\"$relevantAccounts\"\r\n\r\n  # Converts the text data to an HTML table format.\r\n  htmlObject=$(convertToHTMLTable --delimiter ';' \"$htmlObject\")\r\n\r\n  # Tries to set the WYSIWYG custom field using ninjarmm-cli and captures the output.\r\n  if ! output=$(echo \"$htmlObject\" | \/opt\/NinjaRMMAgent\/programdata\/ninjarmm-cli set --stdin \"$_arg_wysiwygField\" 2&gt;&amp;1); then\r\n    echo \"[Error] $output\" &gt;&amp;2\r\n    EXITCODE=1\r\n  else\r\n    echo \"Successfully set Custom Field '$_arg_wysiwygField'!\"\r\n  fi\r\nfi\r\n\r\n# Checks if an error code is set and exits the script with that code.\r\nif [[ -n $EXITCODE ]]; then\r\n  exit \"$EXITCODE\"\r\nfi<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"blog-cta-new blog-cta-style-1\"><div class=\"cta-left\"><h2><\/h2><p><\/p><\/div><div class=\"cta-right\"><a class=\"button\" href=\"\"><\/a><\/div><\/div>\n<h2>An\u00e1lisis detallado<\/h2>\n<p>Desglosemos c\u00f3mo funciona este script para mantener la higiene de las cuentas de usuario en sus sistemas Linux.<\/p>\n<h3>Par\u00e1metros preestablecidos<\/h3>\n<p>El script para detectar las cuentas de usuario inactivas en Linux comienza definiendo los par\u00e1metros preestablecidos:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\">&#8211;daysInactive: el n\u00famero de d\u00edas que una cuenta tiene que estar inactiva para activar una alerta.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\">&#8211;showDisabled: si incluir o no las cuentas desactivadas en el informe.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\">&#8211;multilineField: el nombre de un campo personalizado multil\u00ednea para guardar los resultados.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\">&#8211;wysiwygField: el nombre de un campo personalizado WYSIWYG para guardar los resultados.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\">&#8211;help: muestra el texto de ayuda.<\/li>\n<\/ul>\n<h3>An\u00e1lisis sint\u00e1ctico de argumentos en la l\u00ednea de comandos<\/h3>\n<p>El script para detectar las cuentas de usuario inactivas en Linux emplea una funci\u00f3n para analizar los argumentos de la l\u00ednea de comandos, configurando las variables del script en consecuencia. Si se proporcionan argumentos incorrectos, el script muestra un mensaje de ayuda y sale.<\/p>\n<h3>Detecci\u00f3n de cuentas de usuario inactivas en Linux<\/h3>\n<p>La funci\u00f3n principal consiste en detectar las cuentas de usuario inactivas en Linux. Recupera una lista de cuentas de usuario con UniqueID superiores a 499 (normalmente cuentas que no son de servicio) del directorio de usuarios local. A continuaci\u00f3n, comprueba la \u00faltima fecha de inicio de sesi\u00f3n de cada cuenta y la compara con la fecha actual menos el par\u00e1metro &#8211;daysInactive. Se marcan las cuentas que cumplen los criterios de inactividad.<\/p>\n<h3>Generaci\u00f3n de informes<\/h3>\n<p>Si se detectan cuentas de usuario inactivas en Linux, el script genera una tabla formateada que muestra:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\">Nombre de usuario<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"1\">\u00daltima contrase\u00f1a establecida<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"8\" data-aria-level=\"1\">\u00daltimo inicio de sesi\u00f3n<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"9\" data-aria-level=\"1\">Estado activado<\/li>\n<\/ul>\n<h3>Integraci\u00f3n de campos personalizados<\/h3>\n<p>El script para detectar cuentas de usuario inactivas en Linux puede guardar los resultados en campos personalizados especificados. Formatea los datos en texto plano o HTML, dependiendo de si se guardan en un campo multil\u00ednea o WYSIWYG, respectivamente.<\/p>\n<h2>Posibles casos de uso<\/h2>\n<p>Pensemos en un administrador de TI que gestiona los servidores Linux de una empresa. Las auditor\u00edas peri\u00f3dicas de las cuentas de usuario forman parte del protocolo de seguridad. El administrador programa este script para que se ejecute semanalmente. Una semana, el script detecta varias cuentas inactivas que llevan m\u00e1s de 90 d\u00edas sin conectarse. Tras revisar el informe, el administrador decide desactivar estas cuentas hasta una nueva verificaci\u00f3n, mitigando as\u00ed los posibles riesgos de seguridad.<\/p>\n<h2>Comparaciones<\/h2>\n<p>Otros m\u00e9todos para lograr resultados similares podr\u00edan incluir la auditor\u00eda manual o el uso de herramientas de gesti\u00f3n de usuarios m\u00e1s complejas. La auditor\u00eda manual requiere mucho tiempo y es propensa a errores humanos. Las herramientas avanzadas pueden ser costosas y requerir una instalaci\u00f3n y configuraci\u00f3n exhaustivas. Este script para detectar las cuentas de usuario inactivas en Linux ofrece una soluci\u00f3n sencilla y rentable, lo que lo convierte en un excelente t\u00e9rmino medio.<\/p>\n<h2>FAQ<\/h2>\n<ol>\n<li><strong>\u00bfY si quiero comprobar la inactividad durante un n\u00famero diferente de d\u00edas?<\/strong> Ajusta el par\u00e1metro &#8211;daysInactive en consecuencia. Por ejemplo, utiliza &#8211;daysInactive 60 para comprobar 60 d\u00edas de inactividad.<\/li>\n<li><strong>\u00bfPuedo excluir del informe las cuentas desactivadas?<\/strong> S\u00ed, el script para detectar cuentas de usuario inactivas en Linux incluye el par\u00e1metro &#8211;showDisabled para alternar la inclusi\u00f3n de cuentas deshabilitadas.<\/li>\n<li><strong>\u00bfC\u00f3mo guardo los resultados en un campo personalizado?<\/strong> Especifica los nombres de los campos personalizados mediante los par\u00e1metros &#8211;multilineField o &#8211;wysiwygField.<\/li>\n<li><strong>\u00bfQu\u00e9 ocurre si proporciono par\u00e1metros incorrectos?<\/strong> El script para detectar cuentas de usuario inactivas en Linux mostrar\u00e1 un mensaje de ayuda y saldr\u00e1, asegur\u00e1ndose de que proporcionas los datos correctos.<\/li>\n<\/ol>\n<h2>Implicaciones<\/h2>\n<p>Supervisar regularmente las cuentas de usuario inactivas en Linux tiene profundas implicaciones para la seguridad inform\u00e1tica. Ayuda a impedir el acceso no autorizado, reduce la superficie de ataque y garantiza el cumplimiento de las pol\u00edticas de seguridad. Utilizando este script, los administradores pueden automatizar un aspecto crucial de la gesti\u00f3n de cuentas de usuario, mejorando la seguridad y la eficacia generales.<\/p>\n<h2>Recomendaciones<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"10\" data-aria-level=\"1\">Programa la ejecuci\u00f3n del script para detectar cuentas de usuario inactivas en Linux a intervalos regulares, como semanal o mensualmente.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"11\" data-aria-level=\"1\">Revisa r\u00e1pidamente el informe de cuentas inactivas y toma las medidas oportunas.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"12\" data-aria-level=\"1\">Utiliza la funci\u00f3n de campos personalizados para integrar los resultados con tus herramientas de gesti\u00f3n de TI existentes.<\/li>\n<\/ul>\n<h2>Reflexiones finales<\/h2>\n<p>Gestionar <a href=\"https:\/\/www.ninjaone.com\/es\/eficiencia\/\" target=\"_blank\" rel=\"noopener\">eficazmente<\/a> las cuentas de usuario inactivas es vital para mantener la seguridad inform\u00e1tica. Este script para detectar cuentas de usuario inactivas en Linux ofrece una soluci\u00f3n pr\u00e1ctica y automatizada que permite a los administradores adelantarse a las posibles amenazas contra la seguridad. Si incorporas esta herramienta a tus protocolos de seguridad, podr\u00e1s garantizar un entorno inform\u00e1tico m\u00e1s seguro y conforme a las normas.<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/es\/\" target=\"_blank\" rel=\"noopener\">NinjaOne<\/a> ofrece soluciones integrales de gesti\u00f3n de TI que se integran perfectamente con scripts como \u00e9ste, proporcionando una funcionalidad mejorada y una gesti\u00f3n centralizada para su infraestructura de TI. Adopta la automatizaci\u00f3n y las pr\u00e1cticas de seguridad robustas con NinjaOne para proteger tu organizaci\u00f3n con eficacia.<\/p>\n","protected":false},"author":35,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"","_lmt_disable":""},"operating_system":[4211],"use_cases":[4267],"class_list":["post-353772","script_hub","type-script_hub","status-publish","hentry","script_hub_category-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub\/353772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/comments?post=353772"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media?parent=353772"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/operating_system?post=353772"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/use_cases?post=353772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}