Avoid writing “sudo” while running docker commands in Linux Terminal
sudo usermod -aG docker ${USER}
The command provided above is used to add the current user (represented by `${USER}`) to the `docker` group. The `docker` group is created when you install Docker on your system, and it allows users to run Docker containers without needing to use `sudo` each time, which is more convenient and safer.
Breaking down the command:
- `sudo`: This is used to run the command with administrative privileges. It will prompt you for your password to confirm that you have the necessary permissions to make changes on the system.
- `usermod`: This is the command to modify user account properties.
- `-aG`: The options `-a` stands for “append” and `-G` is followed by the group name. Together, they are used to add the user to the specified group.
- `docker`: This is the name of the group to which you want to add the user. In this case, it’s the `docker` group.
- `${USER}`: This is a shell variable that represents the current username. The value of `${USER}` is automatically substituted with your actual username when you run the command.
After running this command and entering your password, you will be added to the `docker` group, and you will be able to run Docker commands without using `sudo`. Note that for the changes to take effect, you may need to log out and log back in or restart your system.