You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何恢复chmod配置,重新以root身份执行Docker命令

Requiring sudo for Docker Commands Again

Got it, let's get this sorted for you. You mentioned you ran sudo chmod +x /usr/bin/docker to skip typing sudo for Docker commands, but now you want to revert that setup to enforce sudo usage for security reasons. Here's how to do it properly:

Step 1: Restore the Docker binary's default permissions

First, let's fix the permissions on the Docker executable. By default, /usr/bin/docker has permissions set to 755 (readable and executable by all, writable only by root). If you modified this (including adding SUID/SGID bits which might have been the actual way you skipped sudo), run these commands to reset it:

  • Reset to standard 755 permissions:
    sudo chmod 755 /usr/bin/docker
    
  • If you had set a SUID bit (to let non-root users run it as root), remove it:
    sudo chmod u-s /usr/bin/docker
    
  • If you had set a SGID bit, remove that too:
    sudo chmod g-s /usr/bin/docker
    

Step 2: Remove your user from the docker group (if applicable)

Another common way to skip sudo for Docker is adding your user to the docker group. If you did this earlier, you'll need to remove yourself from it to enforce sudo again:

  1. Check if you're in the docker group:
    groups $(whoami)
    
  2. If docker appears in the list, remove your user:
    sudo gpasswd -d $(whoami) docker
    
  3. Log out and log back in for this change to take effect.

Step 3: Verify the setup

Test if the change worked by running a Docker command without sudo, like:

docker ps

You should get a permission error (something like permission denied while trying to connect to the Docker daemon socket). Running the same command with sudo should work normally:

sudo docker ps

That's it! Your Docker setup is now back to requiring sudo for all commands, closing the security loophole you mentioned.

内容的提问来源于stack exchange,提问作者Carlos Andres

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:44:39