diff --git a/ProjectCode/Modules/Security/secharden-2fa.sh b/ProjectCode/Modules/Security/secharden-2fa.sh index 2e7a7e5..f94352d 100644 --- a/ProjectCode/Modules/Security/secharden-2fa.sh +++ b/ProjectCode/Modules/Security/secharden-2fa.sh @@ -240,7 +240,14 @@ function setup_user_2fa() { for user in "${users[@]}"; do if id "$user" &>/dev/null; then print_info "Setting up 2FA for user: $user" - + + local user_home + user_home="$(getent passwd "$user" | cut -d: -f6)" + if [[ -z "$user_home" ]]; then + print_info "No home directory for $user, skipping" + continue + fi + # Create 2FA setup script for user cat > "/tmp/setup-2fa-$user.sh" << 'EOF' #!/bin/bash @@ -257,7 +264,7 @@ EOF chmod +x "/tmp/setup-2fa-$user.sh" # Instructions for user setup - cat > "~$user/2fa-setup-instructions.txt" << EOF + cat > "$user_home/2fa-setup-instructions.txt" << EOF TSYS Two-Factor Authentication Setup Instructions ============================================== @@ -286,7 +293,7 @@ Without them, you may be locked out if you lose your phone. For support, contact your system administrator. EOF - chown "$user:$user" "~$user/2fa-setup-instructions.txt" + chown "$user:$user" "$user_home/2fa-setup-instructions.txt" print_info "2FA setup prepared for user: $user" else print_info "User $user not found, skipping"