General

How To: Add A User To A Group

Today’s article is going to teach you how to add a user to a group. It’s not particularly difficult, but it’s something everyone should know. If you don’t know how to add a user to a group, this article is meant for you.

This article is going to make a few assumptions. The first is that you’re familiar with cat /etc/passwd which will tell you what groups a user belongs to. It also assumes that you’re familiar with cat /etc/group – where you can find supplementary information.

Furthermore, you should also be aware of the groups command, which is a handy command, probably worthy of its own article, that lets you know what groups you already belong to. So, there’s a bit you’re expected to know already, or at least be familiar with conceptually, but trust me when I say this is a very simple article and very straightforward.

Anyhow, if you’ve looked at those previous commands, you’ll see there are a lot of groups. Your user may or may not be a member of those groups, as the groups command will let you know. For myriad reasons, you may wish to add yourself or another user to different groups. Well, that’s what this article is actually about. It’s about showing you how to …

Add A User To A Group:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

The command we’ll be using for this exercise is ‘usermod‘. You can get a head start by using ‘man usermod‘ but we really won’t be needing most of that information. In reality, we only care about a couple of the flags. Still, usermod is a pretty expansive command, with many options. Still, it defines itself simply as:

usermod – modify a user account

See? Pretty straightforward still. The command we actually want is:

sudo usermod -a -G <group_name> <user_name>

The -a means append (add) the user. The -G means groups – so the -a -G means add a user to a group. You can verify the command worked (though, well, you really don’t need to – ’cause, assuming  you did it properly it’ll work) with the following:

grep <user_name> /etc/group

See? That’s it. You’ve learned how to add a user to a group – in under 500 words!

Closure:

Yup, it’s a nice and easy article for a skill you may need as you work with advanced group permissions. If you want to refine the permissions in your system, the sky’s the limit and it’s easy enough to add a user to a group if you need to. So, there’s another tool in your toolbox.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Setting Up Coding Environments on Linux for Educational Use

With so many strong attributes, such as robustness and flexibility, Linux stands as a powerful…

10 hours ago

View Detailed Hardware Information

There are many tools for showing your hardware information and today we'll get to view…

2 days ago

How To: Install Wine In Lubuntu

Today's article isn't going to be complicated or long as we are going to cover…

4 days ago

Update Python Packages (PIP)

We've had a run of Python packages recently and you can tell that I'm a…

6 days ago

Save A Command’s Output To A File (While Showing It In The Terminal)

The title is the best I can come up with to describe this exercise as…

1 week ago

Demystifying journalctl: A Comprehensive Guide to Linux System Logging

It was suggested that I write an article about journalctl, which seemed like a large…

1 week ago