Big Problem - I accidently chmod 000 a lot of files!

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
I was working in a directory and I accidently put chmod -R 000 .*

A lot of my root files and subfolders were chmod 0000!

Anyone know how I could get the regular permissions back, or am I going to have to reload the entire server?
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
asmithjr said:
where were you in / ?
I was in a folder that i created called /downloads

But the -R .* is what I think screwed me. after it did the files in the directory it moved up a directory level and started to do my /
 

asmithjr

Well-Known Member
Jun 13, 2003
516
8
168
I see the .* did it.

what does ls -l / give you
I can give you what I have for the directories but by no means for the entire drive,

If you look into /home for instance and see everything 000 bad news.
 
Last edited:

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
asmithjr said:
I see the .* did it.

what does ls -l / give you
I can give you what I have for the directories but by no means for the entire drive,

If you look into /home for instance and see everything 000 bad news.
The /home directory seems to be ok....but most other directories are 000. I've gone through and tried to match as many of them as I can to another server, but not with much luck....

Some of the hard ones are like the /dev folder.....well all of the files in that folder.


I think the main problem isn't the folders themselves, but all of the files inside those folders iwth the different permissions.....

I think we are screwed....
 

asmithjr

Well-Known Member
Jun 13, 2003
516
8
168
I believe you can use the rdist command to copy files and perms over, that is if you can do r type commands from machine to machine.

either rdist or rsync might do the trick.
Other than that you need a listing of the perms before.

I'll keep thinking. but the rsync looks promising

take a look at the rcync man page.

Code:
You use rsync in the same way you use rcp. You must  specify  a  source
       and a destination, one of which may be remote.

       Perhaps the best way to explain the syntax is some examples:

              rsync *.c foo:src/

       this would transfer all files matching the pattern *.c from the current
       directory to the directory src on the machine foo. If any of the  files
       already  exist on the remote system then the rsync remote-update proto-
       col is used to update the file by sending only the differences. See the
       tech report for details.

              rsync -avz foo:src/bar /data/tmp

       this would recursively transfer all files from the directory src/bar on
       the machine foo into the /data/tmp/bar directory on the local  machine.
       The  files  are  transferred in "archive" mode, which ensures that sym-
       bolic links, devices, attributes, permissions, ownerships etc are  pre-
       served  in  the  transfer.   Additionally,  compression will be used to
       reduce the size of data portions of the transfer.

              rsync -avz foo:src/bar/ /data/tmp

       a trailing slash on the source changes this behavior  to  transfer  all
       files   from  the  directory  src/bar  on  the  machine  foo  into  the
       /data/tmp/.  A trailing / on a source name means "copy the contents  of
       this  directory".   Without  a trailing slash it means "copy the direc-
       tory". This difference becomes particularly important  when  using  the
       --delete option.

       You  can  also  use rsync in local-only mode, where both the source and
       destination don´t have a ´:´ in the name. In this case it behaves  like
       an improved copy command.

              rsync somehost.mydomain.com::

       this  would  list all the anonymous rsync modules available on the host
       somehost.mydomain.com.  (See the following section for more details.)
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
asmithjr said:
I believe you can use the rdist command to copy files and perms over, that is if you can do r type commands from machine to machine.

either rdist or rsync might do the trick.
Other than that you need a listing of the perms before.

I'll keep thinking. but the rsync looks promising

take a look at the rcync man page.

Code:
You use rsync in the same way you use rcp. You must  specify  a  source
       and a destination, one of which may be remote.

       Perhaps the best way to explain the syntax is some examples:

              rsync *.c foo:src/

       this would transfer all files matching the pattern *.c from the current
       directory to the directory src on the machine foo. If any of the  files
       already  exist on the remote system then the rsync remote-update proto-
       col is used to update the file by sending only the differences. See the
       tech report for details.

              rsync -avz foo:src/bar /data/tmp

       this would recursively transfer all files from the directory src/bar on
       the machine foo into the /data/tmp/bar directory on the local  machine.
       The  files  are  transferred in "archive" mode, which ensures that sym-
       bolic links, devices, attributes, permissions, ownerships etc are  pre-
       served  in  the  transfer.   Additionally,  compression will be used to
       reduce the size of data portions of the transfer.

              rsync -avz foo:src/bar/ /data/tmp

       a trailing slash on the source changes this behavior  to  transfer  all
       files   from  the  directory  src/bar  on  the  machine  foo  into  the
       /data/tmp/.  A trailing / on a source name means "copy the contents  of
       this  directory".   Without  a trailing slash it means "copy the direc-
       tory". This difference becomes particularly important  when  using  the
       --delete option.

       You  can  also  use rsync in local-only mode, where both the source and
       destination don´t have a ´:´ in the name. In this case it behaves  like
       an improved copy command.

              rsync somehost.mydomain.com::

       this  would  list all the anonymous rsync modules available on the host
       somehost.mydomain.com.  (See the following section for more details.)
Can you help me out on the syntax of that a bit?

I do have rsync, but can't figure out the exact syntax.

So if I am on the machine that has the bad files:

rsync -avz goodserverhostname:dev/ badhostname:dev/

would that be right?
 

asmithjr

Well-Known Member
Jun 13, 2003
516
8
168
I believe it would be,

From your good server:

# rsync -avz /dev/ badserver:/dev/

not sure if you need the goodserver but pretty sure you need the / infront of dev
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
asmithjr said:
I believe it would be,

From your good server:

# rsync -avz /dev/ badserver:/dev/

not sure if you need the goodserver but pretty sure you need the / infront of dev
I think i got it:

From the good server:

# rsync -avz -e ssh /dev/ [email protected]:/dev/
 

Jemshi

Well-Known Member
Sep 11, 2003
208
0
166
India
noimad1 said:
I was working in a directory and I accidently put chmod -R 000 .*

A lot of my root files and subfolders were chmod 0000!

Anyone know how I could get the regular permissions back, or am I going to have to reload the entire server?
rpm --setperms -a or
rpm --setugids -a

sets all the files/folders ownership, permission and modes to their default. Now, for your home directory and any other manually installed stuff, you have to do separately.

Jemshad O K
Bobcares
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
I really don't think you want to rsync /dev from another box.. That might cause you a problem.

rpm --setperms -a or
rpm --setugids -a
As posted by The man who cares :) is a good idea.

You could always try to run /dev/MAKEDEV $options (to rebuild /dev)

# man MAKEDEV (for more info)
 
Last edited:

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
Jemshi said:
rpm --setperms -a or
rpm --setugids -a

sets all the files/folders ownership, permission and modes to their default. Now, for your home directory and any other manually installed stuff, you have to do separately.

Jemshad O K
Bobcares
Thanks guys...yea I had already done some of the rsyncs and that did cause some problems....like I overwrote my mysql database file that holds all of the mysql users and passwords....that is another mess I'm having to clean up.

I found out the only directory I had left that was causing me problems was the actual ./ directory....took me a long time to find that one....

Thanks again for the help!
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
Jemshi said:
rpm --setperms -a or
rpm --setugids -a

sets all the files/folders ownership, permission and modes to their default. Now, for your home directory and any other manually installed stuff, you have to do separately.

Jemshad O K
Bobcares
I decided to go ahead and run those commands anyways, but I received these errors:

rpmdb: /var/lib/rpm/Packages: unsupported hash version: 8
error: cannot open Packages index using db3 - Invalid argument (22)

?
 

Finley Ave

Active Member
Feb 28, 2004
37
0
156
San Ramon, CA
noimad1 said:
I was working in a directory and I accidently put chmod -R 000 .*
Can someone tell me why .* caused it to go up to a higher directory? Does that .* signify root directory? If I try ls . I get a listing for current directory, but if I try ls .* I get a listing for root directory.
 

Jemshi

Well-Known Member
Sep 11, 2003
208
0
166
India
single dot (.) is your current directory and
double dot (..) is the parent directory

so giving .* includes .. also. Better method to include all the files and folders (starting with dot too) is

chmod -R user.group directory

from its parent directory. And if you want to spare the directory, revert it back with

chmod olduser.oldgroup directory

Or, standing inside the directory,

find . -exec chmod user.grop {} \; will also give the same result

HTH
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
This is actually a common mistake ... I restored a server just at christmas, Christmas day :( for a client that did this

< EDIT referred back to ticket - this is what happened in my case with one client >
# ls -la /tmp
# rm -rf *

Only he wasn't in /tmp - he was in /
</ EDIT>
Believing that it would delete all files in /tmp that were prefixed with .

You should really use the full system path to files when using wildcard deletes and chmod's, it's good practice.
 
Last edited:

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
Finley Ave said:
Can someone tell me why .* caused it to go up to a higher directory? Does that .* signify root directory? If I try ls . I get a listing for current directory, but if I try ls .* I get a listing for root directory.
I don't know if it was the .* by itself. I'm pretty sure it was the -R (recursive) that killed it. Becuase the .* by itself should only change the directory you are currently in. But the recursive does the directory you are in and then goes above it and does all directories above it and so on....
 

dianaward

Well-Known Member
Dec 9, 2002
99
0
156
USA
cPanel Access Level
Root Administrator
Twitter
I thought recursive only went down

directory-wise???
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
dianaward said:
directory-wise???

I believe the .* will actually do the . and the .. - so it will do the current directory and parent directory and anything above it.

Needless to say I have learned my lesson on this one and will be much more careful when it comes to these types of edits....I just got in a hurry and wasn't paying attention.