Skip to content

Command bricked system #168

Closed
Closed

Description

@BumbleTree

Ubuntu 24.02 server
To automate claude updates it advises to run sudo chown -R $USER:$(id -gn) /usr && sudo chmod -R u+w /usr
This bricked the sudo system to no longer work and had to attach a rescue instance to fix the permissions of the files it broke.
I would like to hope this is user error but i dont know how else you would action this request.

Image

Activity

  1. bcherny commented on Feb 27, 2025

    @bcherny
    Collaborator

    cc @sid374 mind taking a look?

  2. MaxKessler5 commented on Feb 27, 2025

    @MaxKessler5

    What I had to do to fix this after mindlessly running the command:

    In recovery mode, drop down into root:

    • chown everything in /usr back to root. sudo chown -R root:root /usr
    • add setuid permissions back to a bunch of things, most important probably being chmod u+s /usr/bin/sudo
    • chown /usr/local to be owned by my username
    • reinstall everything I could find from dpkg --get-selections with apt reinstall (I used a script)
    • apt reinstall more stuff I found with dpkg --verify

    I'm assuming this is a prank, and to be fair, I needed the practice with xargs and awk and stuff, so hey, good one.

  3. emcd commented on Feb 27, 2025

    @emcd
    Contributor

    I tried suggesting to Anthropic that they needed to warn people about this several days ago: #43.

    What the claude program advises is dangerous in terms of security and stability (as can be seen above). People should not be installing the program as root/superuser and the program should not be suggesting that they perform dangerous commands so that it can automatically update. As mentioned in the issue that I filed, Anthropic should update instructions to show people how to install Node packages as a non-privileged user. My experience is that claude works fine as a non-privileged user, installed by a non-privileged user.

  4. ac2522 commented on Feb 27, 2025

    @ac2522

    I was also silly enough to run this.. On Ubuntu 22.04,
    My fix:

    1. Whilst rebooting, hold SHIFT to start Grub
    2. Select "Advanced options for Ubuntu."
    3. Choose the recovery mode
    4. Select "Drop to root shell prompt."
    5. Run:
    mount -o remount,rw /
    chown root:root /usr/bin/sudo
    chmod 4755 /usr/bin/sudo
    chown root:root /usr/libexec/sudo/sudoers.so
    chmod 4755 /usr/libexec/sudo/sudoers.so
    chown root:root /etc/sudo.conf
    chmod 644 /etc/sudo.conf
    
    chmod 755 /usr
    chown -R root:root /usr
    chown -R <your_username>:<your_username> /usr/local
    
    dpkg --get-selections > /tmp/installed_packages.txt
    awk '{print $1}' /tmp/installed_packages.txt | xargs -r sudo apt-get install --reinstall -y
    

    This should theoretically work. However the last command gave me a number of errors with with fuse3, nodejs, and npm. The system now booted and I could uninstall the, purge, fix broken packages and reinstall cleanly.

    *Also I should give credit to Gemini for helping me with this *

  5. ps428 commented on Feb 27, 2025

    @ps428

    Hey @BumbleTree & @ac2522 ,

    I ran into the same issue on my Arch. Here's how I fixed it:

    1. Boot from Arch Linux USB (I had Garuda but a normal Arch bootable pendrive worked too)
    2. Find your main disk using lsblk
    3. Mount it to /mnt: sudo mount /dev/sdXY /mnt (Replace sdXY with your system partition)
    4. Now arch-chroot into the mounted disk: sudo arch-chroot /mnt
    5. Change the ownership back to root: chown -R root:root /usr
    6. Fix the permissions: sudo chmod -R 755 /usr
    7. Reboot

    I had several iterations before I was able to fix it, if these don't work, then just chroot again and run these commands as well:

    chmod u+s /usr/bin/sudo
    chmod u+s /usr/bin/su
    chmod u+s /usr/bin/passwd
    chmod u+s /usr/bin/newgrp
    chmod u+s /usr/bin/gpasswd
    chmod u+s /usr/bin/chsh
    chmod u+s /usr/bin/chfn
    

    For Ubuntu, I think the process should be similar, but use sudo chroot /mnt instead of arch-chroot.

    Hope this helps!

  6. marked Automatic updates command #186 as a duplicate of this issue on Feb 27, 2025
  7. self-assigned this
    on Feb 28, 2025
  8. sid374 commented on Feb 28, 2025

    @sid374
    Contributor

    Sorry about this folks. We are now redirecting to our docs page that helps you set up a user accessible global npm prefix instead of changing permissions:

    https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#auto-updater-permission-options

  9. TLA020 commented on Feb 28, 2025

    @TLA020

    The suggested command breaks your whole system

    sudo chown -R $USER:$(id -gn) /usr/local && sudo chmod -R u+w /usr/local

    broke my sudo command completely. After running this, I received the error:

    "sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set"

    The command in your instructions should be modified to only affect directories needed by the CLI. Modifying permissions recursively across system directories is potentially dangerous and should come with clear warnings. Please consider revising the installation instructions to prevent other users from experiencing this issue.

    How to fix it:

    1. Boot from a live USB (I used EndeavourOS)
    2. Mount your system partition (find it using lsblk):
      sudo mount /dev/nvme0n1p2 /mnt  # replace with your actual system partition
    3. Mount boot partition if separate:
      sudo mount /dev/nvme0n1p1 /mnt/boot  # if needed
    4. Chroot into your system:
      sudo arch-chroot /mnt
    5. Fix permissions:
      chown -R root:root /usr
      chmod -R 755 /usr
      
      # Set setuid bit for critical binaries
      chmod u+s /usr/bin/sudo
      chmod u+s /usr/bin/su
      chmod u+s /usr/bin/passwd
      chmod u+s /usr/bin/newgrp
      chmod u+s /usr/bin/gpasswd
      chmod u+s /usr/bin/chsh
      chmod u+s /usr/bin/chfn
    6. Exit chroot and reboot:
      exit
      sudo umount -R /mnt
      reboot

    I strongly recommend modifying the install instructions to use a more targeted approach for whatever needs sudo-less write access. This recursive permission change is dangerous and should come with clear warnings.

    Maybe nice discount?

  10. oxysoft commented on Mar 2, 2025

    @oxysoft

    I also fell victim to this today and completely destroyed my system. More concerningly, everyone who ran this command and did not break their system is now unknowingly running a severely compromised system where the entire /usr directory is writable by any program run by the user. Neat.

    Here is what Claude has to say about this:

    You're absolutely right to be concerned. That command is extremely problematic and should never have been recommended. It attempts to change ownership and permissions of the entire /usr directory to your user account, which would break many system components - as you've already seen with sudo.

    This issue definitely needs to be reported to Anthropic. The Claude Code CLI should never recommend such a dangerous command that gives blanket write permissions to a critical system directory. That recommendation appears to be a serious error that could cause significant damage to users' systems.

    OpenAI's ChatGPT says this:

    Yeah, that command is absolutely unhinged. No installer should ever recommend recursively changing ownership and permissions for /usr. That’s a surefire way to break a system.

    Claude Code recommending this command is wildly irresponsible. Definitely report this to Anthropic.

    This is extremely bad stuff and needs to be taken seriously. The command has to be removed from the application ASAP.

  11. petenorth commented on Mar 2, 2025

    @petenorth

    Sorry about this folks. We are now redirecting to our docs page that helps you set up a user accessible global npm prefix instead of changing permissions:

    https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#auto-updater-permission-options

    not really good enough, need to do a lot better.

  12. added
    bug
    on Mar 6, 2025
  13. sid374 commented on Mar 6, 2025

    @sid374
    Contributor

    Updating this thread with a troubleshooting guide available here for folks who have run into this issue.

  14. micos7 commented on Apr 8, 2025

    @micos7

    Best part of this,beside me being a lemming pasting commands in the terminal ,is having a fresh install of the latest Ubuntu.

  15. github-actions commented on Aug 11, 2025

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  16. locked as resolved and limited conversation to collaborators on Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions