1

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 ?

Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • Are you currently logged-in to the system, or can login to the system? – Yaron Jun 15 '17 at 09: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. – PoisonAlien Jun 15 '17 at 09: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 '17 at 09:37
  • I cant use sudo. It says sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set – PoisonAlien Jun 15 '17 at 09:40

2 Answers2

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) – PoisonAlien Jun 15 '17 at 11:43
  • It will reinstall most programs. Most settings and themes will be removed, so programs will have to be set up again. – IllustriousMagenta Jun 16 '17 at 01:33
  • Oop, forgot to mention, all your files will be kept – IllustriousMagenta Jun 16 '17 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 :| – PoisonAlien Jun 20 '17 at 08: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 – IllustriousMagenta Jun 21 '17 at 06:48
1

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.