DEV Community

LaTerral Williams
LaTerral Williams

Posted on

🧑‍💻User Account Management in Linux... The Cool Way to Add, Switch, and Delete Users

So, you just spun up a Linux machine (maybe on a VM or in the cloud), and now you want to act like a sysadmin.

Oh just me? Well, I'm here to humble us both because there's a long road ahead...

Still, one of the first things you'll need to know is how to manage users like a pro.

Let's dive into some essential commands: useradd, passwd, su, and userdel.

Think of these commands as your User Control Panel ... but Super Powered, no need for that GUI stuff. 😎


📚 Table of Contents


🔧 useradd – Create New Users

useradd is like the “Create Account” option in Windows, but with style.

Basic Syntax:

sudo useradd [options] username
Enter fullscreen mode Exit fullscreen mode

Common Options:

Option What it does
-m Create the user’s home directory
-d /custom/home Set a custom home directory
-s /bin/bash Set the user’s default shell
-u UID Assign a specific user ID
-g groupname Set the user’s primary group
-G group1,group2 Add the user to supplementary groups
-e YYYY-MM-DD Set account expiration date
-c "Comment" Add a user description

Example:

sudo useradd -m -s /bin/bash -c "Web Developer" alice
Enter fullscreen mode Exit fullscreen mode

🔐 passwd – Set or Change User Passwords

Syntax:

sudo passwd username
Enter fullscreen mode Exit fullscreen mode

Example:

sudo passwd alice
Enter fullscreen mode Exit fullscreen mode

🔁 su – Switch User

Syntax:

su - username
Enter fullscreen mode Exit fullscreen mode

Example:

su - alice
Enter fullscreen mode Exit fullscreen mode

📝 Note: You can use sudo su - to become root, but tread carefully, with great power comes great responsibility... though let’s be real, Peter Parker probably isn't reading this, 🕷️ So maybe just steer clear unless you really know what you're doing!


🧨 userdel – Delete Users

Syntax:

sudo userdel [options] username
Enter fullscreen mode Exit fullscreen mode

Common Options:

Option What it does
-r Remove the user’s home directory and mail spool

Example:

sudo userdel -r alice
Enter fullscreen mode Exit fullscreen mode

🧠 Pro Tips

  • Want to see all user and system accounts?
  cat /etc/passwd
Enter fullscreen mode Exit fullscreen mode
  • Want to check details for a specific user?
  grep <username> /etc/passwd
Enter fullscreen mode Exit fullscreen mode
  • Want to see what groups a specific user belongs to?
  groups <username>
Enter fullscreen mode Exit fullscreen mode
  • Want to check group membership or definitions?
  cat /etc/group
Enter fullscreen mode Exit fullscreen mode
  • Or filter for a specific group:
  grep <groupname> /etc/group
Enter fullscreen mode Exit fullscreen mode
  • Need to modify an existing user (like changing their shell or adding them to groups)?
  sudo usermod [options] username
Enter fullscreen mode Exit fullscreen mode

📝 Note: usermod is a powerful command with lots of options, enough to deserve its own article! From changing usernames to assigning new shells or managing group memberships, it’s a whole-nother rabbit hole. Stay tuned, maybe I'll cover that later.


🪟 Quick Windows Comparison

Windows Action Linux Command
Add a new user (GUI) useradd -m username
Change password (Ctrl+Alt+Del) passwd username
Switch user (Start > Switch user) su - username
Delete user userdel -r username

🏁 Wrapping Up

That’s your crash course on user management! Whether you're building out a secure dev server or managing a personal VM, these commands are must-know tools in your Linux toolkit.

Have fun managing users responsibly. 😄


💬 Let’s Connect

https://www.linkedin.com/in/ltwilliams-tech/

Top comments (0)