Ubuntu grants Docker execution privileges to regular users
In `Ubuntu` systems, by default, `Docker` execution permissions are usually limited to administrator users. This means ordinary users cannot directly run `docker` commands and need to use `sudo` or switch to an administrator user to execute them.
Rendering...
## Background In `Ubuntu` systems, by default, `Docker`'s execution permissions are usually limited to administrator users. This means that regular users cannot directly run `docker` commands and need to use `sudo` or switch to an administrator user to execute them. However, for some developers or users who frequently use `Docker`, this can be inconvenient. Therefore, granting `Docker` execution permissions to regular users is a common requirement, allowing regular users to use `Docker` more conveniently. Article migration: [Lodenhu-Ubuntu Granting Docker Execution Permissions to Regular Users](https://www.lodenhu.com/post/granting-docker-execution-permissions-to-regular-users-on-ubuntu) ## Prerequisites Please ensure that `Docker` is already installed on your `Ubuntu` system. If `Docker` is not installed, you can refer to the article: [Ubuntu Install Docker and docker-compose](https://oldmoon.top/post/185) ## Steps ### 1. Add the user to the `Docker` user group To allow a regular user to execute `Docker` commands, you first need to add that user to the `Docker` user group. Assuming the username you want to add is `username`, you can use the following command to add it to the `docker` user group: ```sh sudo usermod -aG docker username ``` Please replace `username` with your actual username. For example, if the username is `ubuntu`, the command would be `sudo usermod -aG docker ubuntu`. > PS: After installing `Docker`, the `docker` user group is generally created by default, so there is no need to manually create the user group. Simply add the user who you want to have `Docker` permissions to the `docker` user group. If your system does not automatically add the `docker` user group, it means your Docker installation method is not smart enough, and you will have to create the user group yourself and grant Docker executable permissions. This method is not discussed in this article; please refer to other tutorials. > > For operations related to Linux users and user groups, you can read the article: [Linux User and User Group Operations](https://oldmoon.top/post/269) <!-- 文章内嵌广告位 --> <div class="article-ads"></div> ### 2. Re-log in the user After adding the user to the `docker` user group, you need to log out of the current session and log back in for the group membership to take effect. You can log out and log back into the system, or restart the user session using the following command: ```bash su - username ``` Please make sure to replace `username` with the actual username you want to re-log in. ### 3. Verify permission settings After re-logging in, you can verify whether the regular user has execution permissions by running `docker` related commands, such as: ```bash # View docker containers docker ps ``` If you see the correct output, it means your regular user has successfully obtained `Docker`'s execution permissions. ## Summary: Adding a user to the `Docker` user group gives them full access to the `Docker` daemon, which means they can execute any `Docker` command and potentially pose a security risk to the system. 1. Please ensure that only trusted users are added to the `Docker` user group. 2. Make sure `Docker` is installed on your system and that you have administrator privileges to perform installation and configuration operations. 3. After adding a user to the `Docker` user group, remember to re-log in the user for the permissions to take effect. By following these steps, you can grant `Docker` execution permissions to regular users on an `Ubuntu` system, allowing them to more conveniently utilize `Docker` for development and deployment work.
Comments
Please login to view and post comments
Go to Login