I was trying to change ownership of a hard-drive mounted on /media/user/ using command

sudo chwon -R user:user /media/user/

but I made a typo and ran command

sudo chwon -R user:user / /media/user/

Now everything in / is set to user(username) user(group). This system is used by me and my collegue and we cannot ssh into it since permissions have been changed. How do I revert it back to normal ?

  • Are you currently logged-in to the system, or can login to the system?
    – Yaron
    Jun 15, 2017 at 9:28
  • yes, I am still logged in. But my collegue cannot, even I cannot log-in through new ssh. But the existing ssh session is still active. Jun 15, 2017 at 9:30
  • @PoisonAlien - since you are logged in, you can change the ownership of some folder to root (e.g. sudo chown -R root:root /etc and other folders`, to allow SSH login to the system, you'll be able to use it for creating backup of the important staff, and follow by re-installing the system
    – Yaron
    Jun 15, 2017 at 9:37
  • I cant use sudo. It says sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set Jun 15, 2017 at 9:40

2 Answers 2


The quickest and easiest way would take a live CD and reinstall Ubuntu. By selecting upgrade to Ubuntu, you can reinstall while keeping your files. Most applications and setting should remain.

Reference: What if I accidentally run command "chmod -R" on system directories (/, /etc, ...)

  • Thanks, guess this is the best options. Naive question, will it remove other files also ? (as in formatting) and will it also remove all installed softwares ? (so much pain, wish I could go back in time) Jun 15, 2017 at 11:43
  • It will reinstall most programs. Most settings and themes will be removed, so programs will have to be set up again. Jun 16, 2017 at 1:33
  • Oop, forgot to mention, all your files will be kept Jun 16, 2017 at 22:48
  • Turns out you cannot upgrade from live CD or USB. I googled a lot, and this is the case. You can only upgrade from terminal. Using CD you can remove existing and install fresh copy, or install alongside existing OS. I had to do the first one and since I had was only on one partition, I lost all my files :| Jun 20, 2017 at 8:15
  • I upgraded a Virtual Machine running Ubuntu 16.04 to Ubuntu 17.04 losing nothing, and in testing did 17.04 to 17.04 and lost nothing, so not sure what went wrong Jun 21, 2017 at 6:48

In short: No.

For login, you may ssh in using root (if the sshd_config allows root login, otherwise you may need a terminal so to login locally) or the user (this is to match the permission but with a chown / I'm not sure it will work).

You could restore the ownership one by one, for example, /home/user2 belongs to user2, and /var/www to www-data (takes a very long time). Besides that, the only method would be restoring from backup.

Not the answer you're looking for? Browse other questions tagged or ask your own question.