Skip to content

Commit 50b03cb

Browse files
Enable passwordless sudo if user password not set (#106)
1 parent 4d64878 commit 50b03cb

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

du_setup.sh

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

33
# Debian and Ubuntu Server Hardening Interactive Script
4-
# Version: 0.80.2 | 2026-03-01
4+
# Version: 0.80.3 | 2026-03-03
55
# Changelog:
6+
# - v0.80.3: Warn about password-less sudo and offer to genrate password/
67
# - v0.80.2: Added an optional install of netbird (https://netbird.io/) as an alternative to tailscale.
78
# - v0.80.1: Added a safety check to trigger the SSH rollback function if user is disconnected during SSH port change, preventing lockout.
89
# Implement a check for a validated ssh key for the sudo user before revoking root access.
@@ -103,7 +104,7 @@
103104
set -euo pipefail
104105

105106
# --- Update Configuration ---
106-
CURRENT_VERSION="0.80.2"
107+
CURRENT_VERSION="0.80.3"
107108
SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh"
108109
CHECKSUM_URL="${SCRIPT_URL}.sha256"
109110

@@ -262,7 +263,7 @@ print_header() {
262263
printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}"
263264
printf '%s\n' "${CYAN}║ ║${NC}"
264265
printf '%s\n' "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}"
265-
printf '%s\n' "${CYAN}║ v0.80.2 | 2026-03-01${NC}"
266+
printf '%s\n' "${CYAN}║ v0.80.3 | 2026-03-03${NC}"
266267
printf '%s\n' "${CYAN}║ ║${NC}"
267268
printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}"
268269
printf '\n'
@@ -3101,8 +3102,34 @@ setup_user() {
31013102
printf '\n'
31023103
if [[ -z "$PASS1" && -z "$PASS2" ]]; then
31033104
print_warning "Password skipped. Relying on SSH key authentication."
3104-
log "Password setting skipped for '$USERNAME'."
3105-
break
3105+
print_warning "Without a password, you will NOT be able to use 'sudo' for administrative tasks."
3106+
if confirm "Generate a secure random password for you? (Recommended)" "y"; then
3107+
local RAND_PASS
3108+
RAND_PASS=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24)
3109+
if echo "$USERNAME:$RAND_PASS" | chpasswd >/dev/null 2>&1; then
3110+
print_success "Generated random password for '$USERNAME'."
3111+
printf '\n%s\n' "${YELLOW}⚠ SAVE THIS PASSWORD FOR SUDO ACCESS:${NC}"
3112+
printf ' %s\n\n' "${BOLD}$RAND_PASS${NC}"
3113+
log "Generated random password for '$USERNAME'."
3114+
break
3115+
else
3116+
print_error "Failed to set random password. Please try again."
3117+
continue
3118+
fi
3119+
elif confirm "Enable passwordless sudo? (WARNING: Security Risk)" "n"; then
3120+
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/$USERNAME"
3121+
chmod 0440 "/etc/sudoers.d/$USERNAME"
3122+
print_warning "Passwordless sudo enabled for '$USERNAME'."
3123+
log "Passwordless sudo explicitly enabled for '$USERNAME'."
3124+
break
3125+
elif confirm "Would you like to manually type a password instead?" "y"; then
3126+
print_info "Returning to password prompt..."
3127+
continue
3128+
else
3129+
print_warning "Proceeding with NO password and NO sudo rights for '$USERNAME'."
3130+
log "Password setting skipped, no sudo rights for '$USERNAME'."
3131+
break
3132+
fi
31063133
elif [[ "$PASS1" == "$PASS2" ]]; then
31073134
if echo "$USERNAME:$PASS1" | chpasswd >/dev/null 2>&1; then
31083135
print_success "Password for '$USERNAME' updated."

0 commit comments

Comments
 (0)