Messed up Linux permissions – how to fix?

Posted on

Messed up Linux permissions – how to fix? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, permissions, users, , .

I was doing an rsync and accidently reversed the command so it overwrote a bunch a files from our backup server on the main server.

The backup server is in a chroot jail so it overwrote these files:

bin dir:

bash  chroot-jail  cp  ls  mkdir  mv  rm  rmdir  sh  su

dev dir:

null  tty  urandom  zero

lib dir:       pam_krb5  pam_filter




After doing this, on our main server now I can only login as root, none of the secondary accounts work as the permissions seem to be totally screwed up. Apache is just serving up 403 pages, etc. Any ideas on how I can fix this or is the system hosed?

Accounts still seem to be listed in passwd and shadow.

Solution :

As Bill Weiss says, you might find it easier and safer to restore from a known good backup on a clean system. You haven’t just messed up the permissions, but you’ve replaced the files, too. Even if both the source and target machines were the same distribution, there’s no guarantee they’ll be identical files, and that can cause all sorts of wacky problems.

If you feel you must attempt a restore, there’s two ways I an think of going about it. The first is to use your distro’s package manager to to a force-reinstall of the packages owning the affected files. The second is the more manual approach:

  • Use your system’s package manager to find out what owns every one of those files.
  • Set up a new system and ensure you install exactly the same versions of those packages on it
  • Upload a copy of the files to the server
  • Boot the server in single-user mode and carefully replace all the files.
  • Set the permissions/ownership to match.
  • Reboot

You might then find you have a working system again, but I wouldn’t trust it and it would probably take longer than the clean/restore route.

Here’s a useful command you can run on a list of the full paths of the affected files to get a list of affected packages (Debian/Ubuntu):

for a in `cat files.txt`; do dpkg -S $a |cut -d':' -f1; done |sort -u

For the future you may wish to look into rdiff-backup as an alternative to rsync. Specifically because rdiff-backup has a flag to only increment an existing backup, at least then the risk of repeating is gone.

Leave a Reply

Your email address will not be published.