4

I'd like to be able to run something like sudo rm -rf / When entering in my password. Just in case I ever need to wipe everything at once before I even login.

I know there are security concerns, so in a perfect world, I'd like to be able to set it up in .bashrc so I would type in something less obvious.

Anyone know of a way to do this?

Ron
  • 20,938

3 Answers3

8

I would suggest a slightly different approach. Create a new user, let's call him "harakiri" and set it up so that when you log in as harakiri, a command is executed that deletes everything on your hard drive.

  1. Create the new user

    sudo adduser harakiri
    
  2. Create a harakiri script that deletes everything on your drive:

    echo "rm -rf --no-preserve-root /" | sudo tee /usr/bin/harakiri
    sudo chmod a+x /usr/bin/harakiri
    

    We now have the harakiri command which, when run as root, will delete everything on your /.

  3. Add a line to their .profile that will make them run the harakiri script.

    echo "sudo harakiri" | sudo tee ~harakiri/.profile
    
  4. Add them to the sudoers group

    sudo usermod -aG sudo harakiri 
    
  5. Allow user harakiri to run sudo harakiri with no password. Run sudo visudo and add this line:

    harakiri  ALL=NOPASSWD:/usr/bin/harakiri
    

Exit and save the file and that's it. Now, you can just log in as harakiri instead of your normal user and that will delete everything on your drive.


CAVEATS

  1. This is extremely dangerous and can delete everything on your hard drive. Try with a less destructive command first to make sure everything is working as expected.

  2. Even if you delete everything, it is relatively easy for an expert to retrieve your files. You might want to look into utilities like shred.

terdon
  • 104,119
6

If you really need to have this happen when you log in as your regular user, you could also create a bogus X session that runs the rm command.

  1. Create the .desktop file. Run sudo nano /usr/share/xsessions/harakiri.desktop and add these lines:

    [Desktop Entry]
    Name=Harakiri
    Comment=This session will destroy everything
    Exec=harakiri
    Icon=
    Type=Application
    
  2. The rm command needs to be launched as root in order to delete files on / but the sessions are launched as your user. We therefore need an extra script. The first is the session script which in turn will call the one that launched the rm command:

    echo "sudo /usr/bin/harakiri.sh" | sudo tee /usr/bin/harakiri
    sudo chmod a+x /usr/bin/harakiri
    
  3. Create the script that will launch the rm command:

    echo "rm -rf --no-preserve-root /" | sudo tee /usr/bin/harakiri.sh
    sudo chmod a+x /usr/bin/harakiri.sh
    
  4. Give your user the right to run it with no password. Run sudo visudo and add this line:

    youruser  ALL=NOPASSWD:/usr/bin/harakiri.sh
    

Now you will be able to choose the harakiri session from the login screen and that will delete everything on your drive.


CAVEATS

  1. This is extremely dangerous and can delete everything on your hard drive. Try with a less destructive command first to make sure everything is working as expected.

  2. Even if you delete everything, it is relatively easy for an expert to retrieve your files. You might want to look into utilities like shred.

terdon
  • 104,119
1

First of all: what you want to do is not impossible, but more difficult then you think, as you need to:

  1. Boot into a root shell
  2. Execute a delete command (and rm --recursive --force / will not work)

    If you try it out, you'll just get:

    rm --recursive --force /
    rm: it is dangerous to operate recursively on ‘/’
    

So the better option would be to:

  1. How can I securely erase a hard drive?

Or even better:

  1. Enable disk encryption after installation so that no one has access in the first place.

Another piece of free advice: start making back-ups before you even try any of the above.

Fabby
  • 35,017