Skip to content

User And Group Management – Linux Quickie

Concluding this weeks series of quickies about linux user, group, permissions and ownership with a guide for the management of the users and groups.

This week we talked about users and groups. We dug deeper into this topic and stumbled upon permissions and ownerships. Now that we got these basics down, we can conclude the topic with an article about user and group management.

Users

While not crucial to management of the machine, you clearly need at least one user on it. For a multiuser environement you might need more.

Creating User

There are actually a couple of ways to create a user in Linux. (Apparently there are always couple of ways in linux.)

The two options I will talk about in this article will be useradd and adduser. useradd is more low-level, while adduser is more user-friendly. The second one is only available on debian systems. So I will just talk about the useradd, since the other option is easier.

To create a proper user, with home directory and all, you’ll need to add the -m flag. Because obviously -m stands for Mom. And Mom lives at home.

The rest of the usage is pretty linux generic command style: $ sudo useradd -m username

After you create the user, it will have no password. Which is very bad for security reasons. So you have to add a password:

$ sudo passwd newuser

Changin Password

You will probably encounter a lot of users forgetting their passwords. And you will need to change them. Luckily you can change the password, as long as you’re a root user. Unless it’s your own. Then you wont need root power.

The command is the same as actually adding a password:

$ sudo passwd newuser

Groups

Creating Group

This one is similar to creating an user: $ groupadd newgroup

Adding User To Group

Adding users to groups is really important for permission management, if you remember this weeks quickies about it. How do you do it? There are two ways. One is to add the user, after you created it, the other is to add the user to a group, while he’s beeing created:

To add an user after you created him, simply use the usermod command:

$ sudo usermod -a -G that-group username

The -a flag adds/appends the user to the group you specify with the -G flag.

The usermod command is used for generally changing the user you already have created. Not just adding him to a group. But more about it in the links at the end of the article.

To add an user while creating him, you need to specify the group and set a flag accordingly, while creating the user:

$ sudo useradd -m -G groupname username

It’s no surprise that the -G flag is for the group name. Luckily some linux commands follow the same conventions. While others don’t 😓.

Removing User From Group

I think this might be as important as adding the users to a group. Maybe even more (if you make a lot of mistakes…).

You will use a tool called gpasswd which is used for group manipulation, similar to usermod for users.

$ sudo gpasswd -d username groupname

The -d flag is for deleting the user. I love it when the flags make sense. (I’m talking to you useradd -m 😠)

More Usefull Links

 

Published inLinuxQuickies

Be First to Comment

Leave a Reply

%d bloggers like this: