Command bricked system

Status Fixed / completed
Maintainer reply ✓ Yes — bcherny
Activity 12 comments · opened Feb 27, 2025 · closed Feb 28, 2025
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

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

View original on GitHub ↗

12 Comments

bcherny collaborator · 1 year ago

cc @sid374 mind taking a look?

MaxKessler5 · 1 year ago

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.

emcd contributor · 1 year ago

I tried suggesting to Anthropic that they needed to warn people about this several days ago: https://github.com/anthropics/claude-code/issues/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.

ac2522 · 1 year ago

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

ps428 · 1 year ago

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!

sid374 contributor · 1 year ago

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

TLA020 · 1 year ago

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):

``bash
sudo mount /dev/nvme0n1p2 /mnt # replace with your actual system partition
``

  1. Mount boot partition if separate:

``bash
sudo mount /dev/nvme0n1p1 /mnt/boot # if needed
``

  1. Chroot into your system:

``bash
sudo arch-chroot /mnt
``

  1. Fix permissions:

```bash
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
```

  1. Exit chroot and reboot:

``bash
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?

oxysoft · 1 year ago

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.

petenorth · 1 year ago
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.

sid374 contributor · 1 year ago

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

micos7 · 1 year ago

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

github-actions[bot] · 1 year ago

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.