# 创建 Docker 组(如果还没有)
sudo groupadd docker
# 将用户添加到 Docker 组
sudo usermod -aG docker username
#!/bin/bash
# 确认是否提供了用户名参数
if [ -z "$1" ]; then
echo "Usage: $0 <username>"
exit 1
fi
# 获取用户名参数
username=$1
# 创建 Docker 组(如果还没有)
if ! getent group docker > /dev/null; then
sudo groupadd docker
fi
# 将用户添加到 Docker 组
sudo usermod -aG docker "$username"
echo "User '$username' has been added to the Docker group. Please logout and login again for the changes to take effect."