How to reload group assignment without logout and login

Problem

I was working in a shell in KDE. I installed Docker as described here. To be able to run Docker commands, my username should be in the docker group, so I added that. Now I need to logout and login out of my desktop environment for my username’s new group assignments to be picked up. Otherwise, running any Docker command throws this error:

$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.32/images/json: dial unix /var/run/docker.sock: connect: permission denied

We can see that our user’s new group assignment is not reflected in the shell by running this command:

$ id

You will find that the docker group will not appear in the user’s group assignment, though the user has been already added to it. Creating a new shell or a child shell does not achieve what we want.

The only way to get the new group assignment is to logout and login from the desktop environment. The problem I have so many other GUI applications open in my desktop environment. I cannot afford to logout and login from my desktop environment, especially for a shell command to work!

Solution

So, what we want is a shell environment that is similar to what is presented when you login directly at a virtual terminal. Thankfully, we can do that by using the - option of the su command, like this:

$ su - joe
$ docker images
It works!

Another alternative is to run a command with a specific group or GID:

$ sg docker -c "docker images"

Tried with: Docker 17.09 and Ubuntu 16.04

Advertisements

3 thoughts on “How to reload group assignment without logout and login

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.