LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-20-2009, 08:07 AM   #1
littlegreywings
LQ Newbie
 
Registered: Aug 2008
Posts: 11

Rep: Reputation: 0
Accidentally (chmod 755) the whole thing


I meant to run

find . -type d -exec chmod 755 {} \;


on a certain folder, but did it to / by mistake. I ctrl+c'd pretty quick, but I think it did some damage cause now I get an error on one of my webpages (I'm running apahce and mysql).

The error is:

SQLSTATE[HY000]: General error: 1 Can't create/write to file '/tmp/#sql_5916_0.MYI' (Errcode: 13)

When trying to install magento

Last edited by littlegreywings; 03-20-2009 at 08:11 AM.
 
Old 03-20-2009, 08:35 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
chmod 1777 /tmp

Code:
drwxrwxrwt 5 root root 4096 Mar 20 04:02 /tmp
But who knows what else has been messed up by that.
 
Old 03-20-2009, 08:53 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
The best bet could be to reinstall ALL the packages in your system, if your package manager allows that at all, if not I guess that everything will be fixed with the time as packages get updated.

The most important bit if you are running servers of any kind is to revise by hand the permissions in your server directories and files, and in everything under /home and /etc.
 
Old 03-20-2009, 09:00 AM   #4
hatebreeder666
LQ Newbie
 
Registered: Dec 2008
Posts: 17

Rep: Reputation: 0
cool
 
Old 03-20-2009, 09:11 AM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
By the way, I see this same problem regularly but I've never seen anyone doing a backup or the file permissions, it could be a worthy idea to consider if you are afraid of mistakes like these. I never though of this myself, but the idea just came to me and it would be very simple to do so. Something like the following code should backup all the permissions in your system and save them into a plain text file, that you can use for either future reference or even to restore them all using a simple loop to feed chmod:

Code:
find /path/to/ -exec stat --format="%a %n" "{}" \; > chmod.txt
You could even compress that file and since it's a txt file it shouldn't take a lot of space.

Just a random idea I had. Not sure if anyone will care about it

Last edited by i92guboj; 03-20-2009 at 10:35 AM.
 
Old 03-20-2009, 09:21 AM   #6
marvelade
LQ Newbie
 
Registered: Dec 2006
Location: Belgium
Distribution: Mac OS X; Ubuntu 8.04 in a VM
Posts: 29

Rep: Reputation: 16
Quote:
Originally Posted by i92guboj View Post

Just a random idea I had. Not sure if anyone will care about it
I think it's a very good idea, actually. Maybe you could elaborate some more on what steps to take to successfullybackup and restore file perms. I'd use it



grtz,
Marvelade
 
Old 03-20-2009, 10:21 AM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by marvelade View Post
I think it's a very good idea, actually. Maybe you could elaborate some more on what steps to take to successfullybackup and restore file perms. I'd use it



grtz,
Marvelade
Well, let's rescue the line I posted above:

Code:
find /path/to/ -exec stat --format="%a %n" "{}" \; > chmod.txt
Now, let's piece it:

Code:
find /path/to/
This will look into /path/to (change by whatever path you wish, but it must exist) for files of any kind.

Code:
-exec stat --format="%a %n" "{}" \;
This will run "stat" on each one of the found files. What this command will do is to print the permissions and file name for each found file or directory.

Code:
> chmod.txt
Will store the results into a plain text file called "chmod.txt". You can try this yourself, just change /path/to/ by any path in your home, to test. The command doesn't write or erase anything, except in chmod.txt. Then you can open chmod.txt with any text editor to see its contents, you will see two columns, the first one are permissions, the second column is the file name.

This information could be used in these cases to restore the permissions either manually, or using a self made script that reads from this file, and chmods everything accordingly.

I don't know if some serious tool exist for this, but seeying how amazingly simple would be to develop one and the number of persons that ask this same question from time to time here and in another forums, I am surprised that I have never heard of such a tool. And I suspect that maybe it doesn't exist, which is strange.

This is just a quick idea, but it would be simple enough to implement it even with shell scripting. The simples case would be this:

Code:
while read LINE; do PERMS=${LINE%% *}; FILE=${LINE#* }; chmod $PERMS "$FILE"; done < chmod.txt
This will read lines from chmod.txt, separate the permissions from the file names, and issue a chmod command with that info, one chmod per file, restoring the permissions that were saved previously in chmod.txt.

A simple backup system for file permissions. I can't see any downside to using this, BUT if you decide to use this, make your tests. I don't wanna feel responsible if my oneliners fry your pc or kill your kitten hehe

EDIT: Fixed find command
EDIT: Fixed line to restore

Last edited by i92guboj; 03-20-2009 at 10:47 AM. Reason: fixed find commands
 
Old 03-20-2009, 11:34 AM   #8
yanghwanim
LQ Newbie
 
Registered: Mar 2009
Location: Honolulu, Hawaii
Distribution: CentOS/Fedora/Ubuntu/RedHat
Posts: 18

Rep: Reputation: 0
or you could use R1Soft hot copy software which is free. the software allows you to take a snapshot of the system before making changes, and once the changes are made you can always revert back to the point before the change all on the CLI.
 
Old 03-20-2009, 11:47 AM   #9
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I do periodic (daily) / and /home backups using rsync. Rsync copies permissions.

So, faced with this disaster, I could either copy back the rsync'ed files to change the permissions, or I could construct the necessary permissions file as previously suggested, then use it to make repairs.

I can't speak to all the backup programs out there, but I would expect that most would also backup permissions automatically.
 
Old 03-20-2009, 11:59 AM   #10
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by i92guboj View Post
By the way, I see this same problem regularly but I've never seen anyone doing a backup or the file permissions, it could be a worthy idea to consider if you are afraid of mistakes like these. I never though of this myself, but the idea just came to me and it would be very simple to do so. Something like the following code should backup all the permissions in your system and save them into a plain text file, that you can use for either future reference or even to restore them all using a simple loop to feed chmod:

Code:
find /path/to/ -exec stat --format="%a %n" "{}" \; > chmod.txt
You could even compress that file and since it's a txt file it shouldn't take a lot of space.

Just a random idea I had. Not sure if anyone will care about it
I can't believe I've never seen this before either. I've since added it to my daily backup script (with some refinements, namely multiple directories as input) and now I can be sure to have all the critical system permissions saved every day. Incidentally, the bzipped files come to a whopping 89.4K! Well worth the space if you ask me
 
Old 03-20-2009, 12:47 PM   #11
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
watch out for symlinks, stat will return 777 for them, but if you use that value later via chmod it will change the permissions on the file/directory it points to, not the symlink.

So,

Code:
find /path/to ! -type l -exec stat --format="%a %n" "{}" \; >perms.backup

Last edited by GazL; 03-20-2009 at 01:03 PM. Reason: spelling.
 
Old 03-20-2009, 12:52 PM   #12
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
This is an interesting thread because I once did a chown -r tred:tred .* as root from my home directory and wondered (too late!!) why it was taking more than a moment to complete (think about it).

I reinstalled and I learnt to be better with backups.

@pwc101,
It might be thoughtful to post your refinements to i92guboj's script here.
 
Old 03-20-2009, 01:10 PM   #13
mrclisdue
Senior Member
 
Registered: Dec 2005
Distribution: Slackware
Posts: 1,134

Rep: Reputation: 277Reputation: 277Reputation: 277
Yes, this is great stuff. So thanks to all, especially i92guboj, pwc101 and GazL

cheers,
 
Old 03-20-2009, 01:26 PM   #14
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by littlegreywings View Post
find . -type d -exec chmod 755 {} \;
With great power comes great responsibility-- I suggest always running find with -exec with an echo first

Code:
find . -type d -exec echo chmod 755 {} \;
 
Old 03-20-2009, 01:41 PM   #15
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by GazL View Post
watch out for symlinks, stat will return 777 for them, but if you use that value later via chmod it will change the permissions on the file/directory it points to, not the symlink.

So,

Code:
find /path/to ! -type l -exec stat --format="%a %n" "{}" \; >perms.backup
Good catch, well spotted and corrected. That could be a security breach so yes, it's an important thing.

Quote:
Originally Posted by rweaver View Post
With great power comes great responsibility-- I suggest always running find with -exec with an echo first

Code:
find . -type d -exec echo chmod 755 {} \;
I always advice that as well. A simple "echo" thrown in the middle can be used to make sure of what the results would be. Then if you agree you can remove it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Centos 5.0, php-5.2.8 installation, chmod 755 /usr/local/apache2/modules/libphp5.so xxx_anuj_xxx Linux - Server 0 12-30-2008 10:37 AM
would you recommend chmod -R 755 *? CodeFish Linux - Security 2 01-22-2005 10:49 PM
chmod 755 won't change file permission. duffboygrim Linux - General 11 04-29-2004 06:17 PM
Should the apached httpd.conf be chmod to 755? harlow400 Linux - Newbie 6 02-13-2004 11:28 PM
CGI without having to CHMOD 755 all the time. qistoph Linux - Software 9 06-21-2002 07:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration