惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
Engineering at Meta
Engineering at Meta
量子位
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
Recent Announcements
Recent Announcements
博客园 - 司徒正美
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
腾讯CDC
Jina AI
Jina AI
C
Check Point Blog
H
Help Net Security
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
爱范儿
爱范儿
I
InfoQ

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Scaling User Management on Linux: Moving Beyond the Manua...
Lilian S · 2026-06-02 · via DEV Community

Lilian S

The Scenario: The Help Desk Bottleneck

From 2019 to 2021, while serving as Lead Backend Software Engineer at a fast-growing company, I occasionally support our Linux System Administration tasks. When the DevOps team encountered a critical bottleneck during an initiative to scale dozens of new server deployments, I stepped in to streamline the infrastructure processes.

The DevOps team was being hampered by constant, fragmented requests from the help desk to manually create new Linux accounts for recruits testing the latest application. These interruptions were not only time-consuming but were directly preventing the team from focusing on the high-priority infrastructure deployments that define their core responsibilities.

I realized that we weren't just struggling with a task; we were struggling with a scaling bottleneck. To regain the team's focus and ensure we hit our project deadlines, I decided to automate this workflow.

The First Step: The Interactive Script

My first objective was to develop a robust, automated shell script to efficiently create new Linux user accounts. I started with an interactive Bash script (create-user-interactive.sh) that prompted for input.

This was a good educational exercise for learning the fundamentals of Bash—like useradd, passwd, and shell variables. However, I quickly learned that while interactive scripts are great for learning, they are rarely used in professional DevOps environments.

Why Manual Scripts Don’t Scale

As I transitioned into a more infrastructure-focused role, I realized that manual scripts fail for three key reasons:

  • Lack of Automation: DevOps is about "Infrastructure as Code" (IaC). Asking an engineer to sit at a terminal and type prompts is slow, error-prone, and destroys the ability to automate.

  • Lack of Centralization: In a real team, we aren't creating users on individual local machines. We manage identity across hundreds of servers.

  • Security Risks: Hardcoding passwords or piping them through echo is a major red flag.

The Industry Standard: How We Actually Do It

If you are working in a industry-standard DevOps team, you don't use manual scripts for user management. You use one of the following methods:

  • Configuration Management (Ansible, Puppet): We define the state of the user in a configuration file. Ansible is my favorite here because it is idempotent—if the user already exists, it does nothing; if they are missing, it creates them.

  • Centralized Identity (LDAP, Active Directory): In an enterprise, we connect servers to a central directory. When an employee leaves, we disable their account in one place, and they lose access everywhere instantly.

  • Cloud-Native IAM (AWS/GCP IAM): For cloud infrastructure, we often skip OS-level accounts entirely, using services like AWS SSM Session Manager to connect to instances without managing local users or SSH keys.

The Pragmatic Solution: create-user-automated.sh

Sometimes, you still need a shell script. Perhaps you are working on a small project or need a bootstrap script for a server's first boot. If you must use a script, make it non-interactive so it can be automated by a CI/CD pipeline.

Here is the "DevOps" way to write that script (create-user-automated.sh):

#!/bin/bash
#
# Name: create-user-automated.sh
# Description: Creates a new user on the local system non-interactively.
# Usage: ./create-user-automated.sh <username> <full_name> <password>
# Example call: ./create-user-automated.sh jdoe "John Doe" "P@ssw0rd"


# Ensure the script is run as root
if [[ "${UID}" -ne 0 ]]; then
    echo 'Error: Please run with sudo or as root.' >&2
    exit 1
fi

# Check for correct number of arguments
if [[ "${#}" -ne 3 ]]; then
    echo "Usage: ${0} <username> <full_name> <password>" >&2
    exit 1
fi

USER_NAME="${1}"
COMMENT="${2}"
PASSWORD="${3}"

# Check if user already exists to maintain idempotency
if id "${USER_NAME}" &>/dev/null; then
    echo "User ${USER_NAME} already exists. Skipping creation."
    exit 0
fi

# Create the account
useradd -c "${COMMENT}" -m "${USER_NAME}"
if [[ "${?}" -ne 0 ]]; then
    echo "Error: Could not create account for ${USER_NAME}." >&2
    exit 1
fi

# Set the password
echo "${PASSWORD}" | passwd --stdin "${USER_NAME}" &>/dev/null
if [[ "${?}" -ne 0 ]]; then
    echo "Error: Could not set password for ${USER_NAME}." >&2
    exit 1
fi

# Force password change on first login
passwd -e "${USER_NAME}" &>/dev/null

echo "User ${USER_NAME} successfully created on ${HOSTNAME}."
exit 0

Enter fullscreen mode Exit fullscreen mode

The Engineer’s Mindset

Moving from a manual, interactive script to an automated, idempotent one isn't just about writing cleaner code—it’s about a change in mindset. It’s about building systems that don't require our constant presence to function.

By building this tool, I empowered the help desk to handle requests independently, ensured our provisioning was consistent and error-free, and most importantly, I regained the time I needed to focus on our high-priority server deployments.