How to Recover Ubuntu 10.04 After Accidental “sudo chmod -R 777 /” Permission Changes


3 views

Running sudo chmod -R 777 / on a Linux system is one of the most destructive commands you can execute. This recursively grants read, write, and execute permissions to all users for all files in your root directory, including critical system files like:

  • /etc/shadow (stores encrypted passwords)
  • /etc/passwd (user account information)
  • SSH keys in /etc/ssh/
  • System binaries in /bin, /sbin

Ubuntu 10.04 (Lucid Lynx) uses several security mechanisms that break when file permissions are too open:

# Example error you might see in logs:
init: ureadahead main process (1234) terminated with status 4
init: plymouth-upstart-bridge main process (1256) terminated with status 1
/bin/sh: /etc/init.d/rc: Permission denied

Prerequisite: You'll need a Live CD/USB of Ubuntu 10.04

1. Boot into Live Environment

Insert your Live media and choose "Try Ubuntu"

2. Mount the Broken System

Identify your root partition (usually /dev/sda1):

sudo fdisk -l
sudo mount /dev/sda1 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

3. Reset Critical Permissions

Create a repair script with these essential commands:

#!/bin/bash
# Core directory permissions
chmod 755 /mnt/bin /mnt/boot /mnt/etc /mnt/home /mnt/lib /mnt/opt
chmod 755 /mnt/root /mnt/sbin /mnt/usr /mnt/var

# Critical binaries
chmod 755 /mnt/bin/* /mnt/sbin/* /mnt/usr/bin/* /mnt/usr/sbin/*

# SSH and authentication files
chmod 600 /mnt/etc/ssh/*_key
chmod 644 /mnt/etc/ssh/*.pub
chmod 600 /mnt/etc/shadow
chmod 644 /mnt/etc/passwd /mnt/etc/group

For more thorough repairs, use dpkg to reset all package file permissions:

sudo chroot /mnt
for pkg in $(dpkg -l | awk '{print $2}'); do 
    dpkg --reconfigure --force-all $pkg
done

Create a safety net before making permission changes:

# Backup current permissions
find / -type f -printf "%m %p\n" > /root/permissions_backup.txt
find / -type d -printf "%m %p\n" >> /root/permissions_backup.txt

# Restore script template
awk '{print "chmod", $1, $2}' /root/permissions_backup.txt > restore_perms.sh

Remember: Never run recursive chmod on root unless you're absolutely certain of the consequences. When in doubt, test permission changes in a VM first.


Executing sudo chmod -R 777 / is one of the most destructive commands you can run on a Linux system. This recursively removes all permission restrictions on every file and directory starting from root, effectively:

  • Breaking system security (SSH, sudo, etc.)
  • Preventing proper boot sequences
  • Corrupting package manager functionality

First, you'll need to boot into a recovery environment:

# For physical machines:
1. Use Ubuntu Live CD/USB
2. Select "Try Ubuntu" option
3. Open terminal

# For cloud instances:
1. Detach root volume
2. Attach to temporary instance
3. Mount for repair

Here's a step-by-step repair method:

# Mount the damaged filesystem
sudo mount /dev/sda1 /mnt

# Restore base permissions
sudo chmod 755 /mnt
sudo chmod 600 /mnt/etc/shadow
sudo chmod 644 /mnt/etc/passwd

# Critical system directories
for dir in bin boot etc lib sbin usr var; do
    sudo find /mnt/$dir -type d -exec chmod 755 {} \;
    sudo find /mnt/$dir -type f -exec chmod 644 {} \;
done

# Special permissions
sudo chmod 4755 /mnt/bin/sudo
sudo chmod 4755 /mnt/bin/ping
sudo chmod 1777 /mnt/tmp

For more thorough restoration, use this script (save as repair_perms.sh):

#!/bin/bash
MNT=/mnt

# Core system permissions
declare -A special_perms=(
    ["$MNT/bin/su"]="4755"
    ["$MNT/usr/bin/sudo"]="4755"
    ["$MNT/var/log"]="775"
)

# Apply standard permissions
find $MNT -type d -exec chmod 755 {} \;
find $MNT -type f -exec chmod 644 {} \;

# Apply special permissions
for file in "${!special_perms[@]}"; do
    if [ -e "$file" ]; then
        chmod "${special_perms[$file]}" "$file"
    fi
done

# Restore critical configs
chmod 600 $MNT/etc/shadow $MNT/etc/gshadow
chmod 644 $MNT/etc/passwd $MNT/etc/group

After repair, verify critical services:

# Check sudo functionality
sudo -l

# Test authentication
su - [username]

# Verify boot files
ls -l /boot/vmlinuz-*
stat /etc/init.d/

To prevent recurrence:

# Create admin alias
echo "alias sudo='sudo '" >> ~/.bashrc
echo "alias chmod='chmod --preserve-root'" >> ~/.bashrc