Sudo Groupadd Docker

While the useradd command creates new users, the groupadd command in Linux creates new groups. It updates the /etc/group file accordingly.

If not, Do the following steps to create docker group and run docker without sudo. First, Create the docker group: sudo groupadd docker. Then, Restart the docker service. (This is important): systemctl restart docker. Now, you can add the non root user to the docker group, (Replace the 'username' with actual username): gpasswd -a username docker. If you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group. Warning: The docker group grants privileges equivalent to the root user. To enable users other than root and users with sudo access to be able to run Docker commands: Create the docker group: # groupadd docker. Restart the docker service: # service docker restart. The UNIX socket /var/run/docker.sock is now readable and writable by members of the docker group. Add the users that should have Docker access to the.

Docker

There are not many options with groupadd and its syntax is pretty basic:

Let’s see how to use groupadd command for creating groups in Linux.

Groupadd command examples

Please keep in mind that adding group is administrative task and hence you need to be root or have sudo rights. Read more about creating sudo user here.

1. Create a new group

To create a new group in Linux, you can use it in the following manner:

You can verify that the new group has been created by checking the /etc/group file:

What do you do with a group? You should have some users in it, right? You can add users to group using the usermod command. If you want to add multiple users to a group at the same time, you can use the gpasswd command like this:

2. Create a group with specific group ID (gid)

By default, the new group gets created with a group id higher than the GID_MIN value defined in /etc/login.defs. On most Linux system, this value is 1000.

In other words, you get one of the first available GID after 1000.

But you are not restricted to that. You can create a group with a specific GID in this manner:

Groupadd

Here’s an example:

3. Create a new system group

When you create a new group, it’s a normal group with GID higher than 1000. You can also create a system group that automatically takes a group id between SYS_GID_MIN and SYS_GID_MAX as defined in /etc/login.defs.

You can see in the example that the group id is less than 1000 and thus indicating that it is not a normal group but a system group (used for system programs).

Sudo Groupadd Docker Commands

I hope you find this quick little tutorial helpful in using groupadd command. You may also checkout how to delete groups with groupdel command.

Sudo Groupadd Docker Login

Any questions or suggestions are always welcomed.