How do I backup my files from TTY login

I mistakenly changed permission recursively, issuing the following command on many files, including /usr/bin/sudo:

chown -R $USER:$USER sudo

Now I want to reinstall my Ubuntu OS but I need to back up my files on my external hard disk from the TTY. How do I do that step by step?

I currently do not have access to a Ubuntu installation medium and I don't want to loose my files.


I need to back up my files on my external hard disk from the TTY.

You can't do it precisely from the TTY because you destroyed your sudo ability and probably you won't be able to mount the external drive. However, you have two options:

  • booting in a root shell
  • using a live DVD or USB

Backup booting in a root shell

You cut yourself superuser powers, so you need to "hack" your own computer. As I explained in a slightly related answer:

Boot your PC while holding Ctrl+Shift, you should see the GRUB menu appear. While focusing on the first Ubuntu entry, press e to edit it.

You should see a line which ends with ro quiet splash --. Change this last part to:

rw verbose init=/bin/bash --

Don't touch the first part of the string, leave it the same as before. Now press Ctrl+X to boot. You should boot straight into a root shell.

Now you have root access and you can connect your external drive. After connecting it, wait a few seconds and do:

dmesg | tail

It will show a few lines where you can detect the device associated with the main partition of the external drive, probably /dev/sdb1. Create a mount point and mount the partition:

mount -o remount,rw /
mkdir -p /mnt/external
mount /dev/sdb1 /mnt/external

Now prepare an output directory and copy the files:

mkdir /mnt/external/RECOVERED
cp -v -r /home /mnt/external/RECOVERED/

Note: if your home directory is in a separate partition you might need to mount it before doing the above. In that case mount /home should suffice.

When it's done, assure the data is written on the drive completely and unmount the file system:

sync
umount /mnt/external

Disconnect the external drive now. Since you plan to reinstall, I won't discuss how to clean up and shut down the computer safely. Just long-press the hardware power button. ;)

Backup using a live DVD or USB

If you have access to a Ubuntu installation medium, do the following:

  • boot your computer using the live DVD or USB
  • connect the external hard drive
  • run sudo nautilus in the terminal
  • copy all the files you want in the external drive
  • safely disconnect the drive
  • re-install Ubuntu