You are not logged in.

#1 2011-08-05 15:00:51

mdschechtman
Member
Registered: 2011-05-26
Posts: 14

[SOLVED] Incorrect File Permissions

I did something very stupid involving a recursive chmod in the wrong directory.  I realized my mistake right away and stopped the execution, but I don't know how many files got hit.  I at least know /usr/bin got changed since I get the wonderful "sudo: must be setuid root". 

Is it practical to try and fix some of the file permissions in single user mode or should I just wipe and reinstall Arch? It's a relatively clean/recent installation.

Last edited by mdschechtman (2011-08-05 17:12:11)


Tide goes in, stain comes out. Never a miscommunication.

Offline

#2 2011-08-05 16:29:19

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Incorrect File Permissions

You can spot the affected files using `find', e.g.,

find / -cmin -60

will find the files changed in the last 60 minutes.

From there, you may try reinstalling the relevant packages, e.g.,

#!/bin/bash

dir=/   # Find files in $dir
min=60  # Find files changed in the last $min minutes

readonly dir min
declare -A pkgs

while IFS= read -r -d '' file; do 
  pkg=$(pacman -Qoq "$file") || continue
  pkgs[$pkg]+=" $file"
done < <(find ${dir} ! -type d -cmin -${min} -print0)

printf ":: The following packages are changed in the last $min minutes...\n" >&2
for pkg in "${!pkgs[@]}"; do
  printf "%s:%s\n" "$pkg" "${pkgs[$pkg]}"
done

pacman -S "${!pkgs[@]}"

printf ":: The following directories may need manual correction...\n" >&2
while IFS= read -r -d '' file; do 
  ls -lcd "$file"
done < <(find ${dir} -type d -cmin -${min} -print0)

You can try running this script as root. Modify dir and min as needed.
Also, what exactly did you? What command? Which directory?


This silver ladybug at line 28...

Offline

#3 2011-08-05 16:36:29

mdschechtman
Member
Registered: 2011-05-26
Posts: 14

Re: [SOLVED] Incorrect File Permissions

lolilolicon wrote:

Also, what exactly did you? What command? Which directory?

While setting up my new system, I was extracting some configuration files (.bashrc, .vimrc, etc.) to all of my user's home directories, including root.  The ownership and permissions were set to the user that downloaded the archive, so to change it over to the correct user, in this case root, I did "# chown -R root:root .*", or at least I thought I did. When I noticed it taking longer than expected, I knew I was doing some deep recursion.  In my panic, I forgot to check which directory I ran the command from.


Tide goes in, stain comes out. Never a miscommunication.

Offline

#4 2011-08-05 17:03:32

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Incorrect File Permissions

mdschechtman wrote:

I did "# chown -R root:root .*", or at least I thought I did.

So you did `chown', not `chmod' as you initially stated. If you did run that command, with ".*" as argument, it should have only changed the hidden files and directories recursively. But you seem unsure about the actual command you ran? Try `history | grep chown' maybe...

mdschechtman wrote:

In my panic, I forgot to check which directory I ran the command from.

OK. My script should be able to fix the system files, provided you adjust $min accordingly.
On the other hand, since you don't have an idea which directory is affected, `find' needs to do a lot of work on the whole /, you might as well just reinstall all of your packages... i.e. `pacman -S $(pacman -Qq)'. (Edit: Note though, pacman will not fix permissions or ownership of directories, but will, AFAIK, print a warning when they differ).

Next time... Remember, don't panic!!!1

Last edited by lolilolicon (2011-08-05 17:09:31)


This silver ladybug at line 28...

Offline

#5 2011-08-05 17:11:52

mdschechtman
Member
Registered: 2011-05-26
Posts: 14

Re: [SOLVED] Incorrect File Permissions

Next time I'll remember my HGTTG...

I would check the bash history, but I can't su to root.  Doing so tells me the password is incorrect.  I know for a fact the password is indeed correct, so I assume it's a permissions or ownership issue.

I was SSHing into the machine so I can't try your script in single user mode until the end of the work day. Yeah, I know... I was slacking off.  If it doesn't work, I'm just going to do a clean installation.

For anyone that is as dumb as me has this problem in the future: You can try lolilolicon's script or reinstall, which is pretty much a guarantee that the problem will be solved.

Thanks for the help!

Last edited by mdschechtman (2011-08-05 17:13:42)


Tide goes in, stain comes out. Never a miscommunication.

Offline

#6 2011-08-05 20:15:06

lukaszan
Member
Registered: 2011-05-05
Posts: 117

Re: [SOLVED] Incorrect File Permissions

lolilolicon wrote:

If you did run that command, with ".*" as argument, it should have only changed the hidden files and directories recursively.

No. It will also do '.' and '..' (so entire current and parent directory). Or to be more precise, with -R option, it will do from parent directory down recursively. Been there myself...

Last edited by lukaszan (2011-08-05 20:17:03)

Offline

#7 2011-08-06 02:54:07

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Incorrect File Permissions

Ah, you're right!  *Adding ".*" to my evil devil list*
Maybe there's a shell option to change this behavior... or we'd have to use ".[^.]*" instead... (but ..foo will be lost) :S


This silver ladybug at line 28...

Offline

Board footer

Powered by FluxBB