So you’re managing your personal Ubuntu machine or administering a server, understanding how to handle users and groups can really make your life easier.

🚀 Creating Users: System and Normal

For the Regular Users Creating a normal user is like inviting a new friend to your Ubuntu party. Simply pop open your terminal and type:

sudo adduser tonystark

This command conjures up a new user named tonystark, complete with a home directory and an interactive process to set up the account.

For the System User They’re not for daily use but for running services and applications. To create one, do a little terminal magic with:

sudo adduser --system my-awesome-service-user

This creates a system user without a home directory by default.

🧙‍♂️ Conjuring Groups and Modifying Memberships

Creating a Group: To start a new group, simply:

sudo addgroup codingwizards

Now codingwizards is ready for members!

Adding a User to a Group: Got a user that needs to be in a group? No problem!

sudo adduser newfriend codingwizards

Voilà! newfriend is now a proud member of the codingwizards.

Forming a Group After the Fact: Did you forget to add your user to a group during their creation? Fear not!

sudo usermod -aG codingwizards newfriend

The -aG option appends the user to the specified group without removing them from their current groups.

🚫 Going NoLogin and Setting Up Shop (Home Directories)

Silencing the Login: Want a user that can’t login? It’s great for system users running services:

sudo usermod -s /usr/sbin/nologin ghostlyassistant

Now, ghostlyassistant can’t log in, which is perfect for a background service user.

Creating a Home After the Fact: Forgot to give your system user a place to live? Let’s fix that:

sudo mkdir /home/ghostlyassistant
sudo chown ghostlyassistant:ghostlyassistant /home/ghostlyassistant

And just like that, ghostlyassistant has a cozy home in your system.

🆔 Assigning Specific IDs

Sometimes, you need to get specific about user and group IDs for various reasons (like matching permissions across systems).

User ID (UID):

sudo useradd -u 1001 specialuser

Group ID (GID):

sudo groupadd -g 2001 specialgroup

And there you have it, specialuser and specialgroup with custom IDs.

🌈 Removing Users and Groups

Sometimes, parties end, and it’s time to say goodbye:

To remove a user:

sudo deluser oldfriend

To dissolve a group:

sudo delgroup oldclub

Just like that, oldfriend and oldclub are part of your system’s history.



Buy Me a Coffee