Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

Accidentally chmod'd everything 777

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
22 posts • Page 1 of 1
Author
Message
jamori
n00b
n00b
Posts: 4
Joined: Wed Dec 07, 2005 12:14 am

Accidentally chmod'd everything 777

  • Quote

Post by jamori » Wed Dec 07, 2005 12:23 am

I seem to have accidentally chmod'd my entire system a+rwx

I issued the following command:

Code: Select all

sudo chmod a+rwx /my/dir -R *
which I know isn't the right order, but I'd already typed a long pathname and didn't want to arrow back and add flags to the beginning. I figured that the program would either a) figure out what I meant or b) tell me it couldn't and bail.

Instead, the permissions on every file on my system are bork'd. Any recommendations on how to get the standard files back to how they should be other than going through manually? I'll obviously have to redo any special files/folders I made, but how about all the standard system stuff?
I'd like to preserve all my config files. Would a forced re-emerge world do it?

Any suggestions would be greatly appreciated.
Top
timeBandit
Bodhisattva
Bodhisattva
User avatar
Posts: 2719
Joined: Fri Dec 31, 2004 1:54 am
Location: here, there or in transit

Re: Accidentally chmod'd everything 777

  • Quote

Post by timeBandit » Wed Dec 07, 2005 1:48 am

jamori wrote:I figured that the program would either a) figure out what I meant or b) tell me it couldn't and bail.
... Any recommendations on how to get the standard files back to how they should be ... ? Would a forced re-emerge world do it?
I bet you won't make that assumption again. :wink:
Almost. I think your best bet is:

Code: Select all

emerge -e system
emerge -e world
plus manual fixes to your own files. After the re-merge, you can do this to locate stragglers and decide whether they require correction:

Code: Select all

find / -perm -0777 -a ! -type l -ls
The ! -type l (that's ell,) predicate excludes symbolic links, which always have mode 777. As a point of reference, on my machine that command finds exactly 23 files.

If you haven't already upgraded to GCC 3.4, now might be a good time--a full re-merge is part of the job.
Last edited by timeBandit on Wed Dec 07, 2005 3:15 am, edited 1 time in total.
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Top
jamori
n00b
n00b
Posts: 4
Joined: Wed Dec 07, 2005 12:14 am

Re: Accidentally chmod'd everything 777

  • Quote

Post by jamori » Wed Dec 07, 2005 1:56 am

timeBandit wrote:I bet you won't make that assumption again. :wink:
definitely not.

Thanks for the advice; it was greatly appreciated.

For some reason, all my services work except ssh (I get connection refused), so I'm going to have to drag it out of a closet to fix this. *sigh*

Thanks again.
Top
timeBandit
Bodhisattva
Bodhisattva
User avatar
Posts: 2719
Joined: Fri Dec 31, 2004 1:54 am
Location: here, there or in transit

Re: Accidentally chmod'd everything 777

  • Quote

Post by timeBandit » Wed Dec 07, 2005 3:14 am

jamori wrote:For some reason, all my services work except ssh (I get connection refused), so I'm going to have to drag it out of a closet to fix this. *sigh*

Thanks again.
You're welcome. As for SSH, it's fussy about permissions on certain critical directories/files (security risk), and will deny connections if they are incorrect. In particular, IIRC the host private keys and sshd_config need to be owned by root, readable only by root (0600), and the directory /var/empty must exist (with permissions 0755). There are probably more such constraints--I'm sorry, it's been a while since I set up SSH, so I can't say which may be at fault. It is mentioned in the config file comments and/or man pages, though, so with some reading you should be able to puzzle it out. Check the logs, too.

Good luck.
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Wed Dec 07, 2005 5:46 am

Moved from Other Things Gentoo
Quis separabit? Quo animo?
Top
wjholden
l33t
l33t
Posts: 826
Joined: Mon Mar 01, 2004 2:59 am
Location: Augusta, GA
Contact:
Contact wjholden
Website

  • Quote

Post by wjholden » Wed Dec 07, 2005 7:59 am

I remember having problems after a "chmod 777 -R /some/directory" with a lot of stuff in it, which happened to be content on an FTP server (or something). Because I knew there were some perl scripts in teh folder that I didn't want to be executed, it shouldn't have been possible for any user to execute them anyways, but you can't be too careful, and I fell in love with the "find" command like this:

Code: Select all

chmod -R a-x /some/directory
find /some/directory -type d -exec chmod a+x {} \;
Directories need to be executable (otherwise you can't "cd" into them).

Plus...this might not be a problem with you guys, but I find "a.out" files everywhere ;)
Top
humbletech99
Veteran
Veteran
User avatar
Posts: 1229
Joined: Thu May 26, 2005 9:30 am
Location: London

  • Quote

Post by humbletech99 » Thu Dec 29, 2005 1:18 am

This is a beginners experimental mistake, but some people actually like this sort of thing cos it makes everything more open and therefore easier, you don't get lots of access denied... etc, it's why people also run as root all the time. I'd say chalk it up to experience and do a fresh install, I get the impression you haven't been into Linux for too long so there probably isn't much to lose and it might be quicker than try to fix it. If you do want to try to fix it, the chmoding -R 755 / and then adjusting the rest like home dir and the occasional suid or special case may be the only way to go, but it's the long way round. You could try doing a deep emerge world and rebuild everything and see if that replaces everything with their correct permissions

Beware the power of linux, unlike Windows, it assumes you're smart enough to know what you're doing, it doesn't have stabilizers.


For your amusement (probably more for our own really), here's a relevent quote from this forum:

Gentree wrote:
I tell you with the new flux of -ex windows users piling onto Linux we'll be the same mess as Winworld within a year. :cry:
from the following post http://forums.gentoo.org/viewtopic-p-29 ... ml#2989221
Top
mephx
n00b
n00b
Posts: 11
Joined: Thu Nov 23, 2006 7:14 am
Contact:
Contact mephx
Website

File Permissions

  • Quote

Post by mephx » Thu Dec 14, 2006 8:45 am

well, accidentaly chmoded 777 ./.* as root, then went away for a smoke, when i was back, jeez, my box looks like a bit&/%!! is there any fast way to re-perm all the fs?

by hand may be out of question :S

thanks
Top
fangorn
Veteran
Veteran
User avatar
Posts: 1886
Joined: Sat Jul 31, 2004 1:31 pm
Contact:
Contact fangorn
Website

  • Quote

Post by fangorn » Thu Dec 14, 2006 9:08 am

As gentoo systems are quite different from box to box, I dont think there are some scripts to repermission everything.

The most complete way (and with the minimum of handwork) is to just repermission your /home and /etc and rebuild the system with a stage3, copy the handedited files from /etc/, your /home and world file and "emerge -e world".
Video Encoding scripts collection | Project page
Top
lxg
Veteran
Veteran
User avatar
Posts: 1019
Joined: Sat Nov 12, 2005 3:12 pm
Location: Aachen, Germany
Contact:
Contact lxg
Website

  • Quote

Post by lxg » Thu Dec 14, 2006 1:28 pm

Maybe I'm on the wrong path, but wouldn't in this specific situation an emerge -e world suffice?
lxg.de – codebits and tech talk
Top
mephx
n00b
n00b
Posts: 11
Joined: Thu Nov 23, 2006 7:14 am
Contact:
Contact mephx
Website

  • Quote

Post by mephx » Thu Dec 14, 2006 4:59 pm

thanks,

even so... i'm currently on a deadline approach, so no emerge world for 200 and some change packages.

chmoded most of the fs by hand.

there should be an easy way to store/restore perms. portage or not :D

cheers
Top
PaulBredbury
Watchman
Watchman
User avatar
Posts: 7310
Joined: Thu Jul 14, 2005 3:47 pm

  • Quote

Post by PaulBredbury » Thu Dec 14, 2006 5:13 pm

lxg wrote:an emerge -e world suffice?
No, because re-emerges don't reset the permissions of existing files. Unless they do so in e.g. pkg_postinst(), outside of the sandbox. Or unless Portage has got a bug.

Edit: Hmm, just experimented with /etc/conf.d/microcode_ctl and portage-2.2_rc22, and portage *did* reset the file's permissions after an emerge. Toss a coin, to determine Portage's behaviour this week :?
Last edited by PaulBredbury on Thu Jan 15, 2009 2:48 am, edited 1 time in total.
Top
chris.c.hogan
Apprentice
Apprentice
Posts: 189
Joined: Sun Oct 02, 2005 9:29 am

  • Quote

Post by chris.c.hogan » Thu Dec 14, 2006 7:20 pm

mephx wrote:accidentaly chmoded 777 ./.* as root
I'm assuming you used chmod -R 777 ./* from root as root. chmod 777 ./.* would only have changed the permissions on hidden files in the current directory. Either way, it would make the files in question user/group/world readable/writable/executionable. It makes for an insecure system. However, with the exception of files that need to be setuid/setgid, your system should function. Of course you'll want to repair the damage.
mephx wrote:there should be an easy way to store/restore perms. portage or not
If you are just interested in backing up and restoring permissions, you could do:

Code: Select all

cd /
ls -Rl > backup.perms
You could then write a script that feeds the generated list back into chmod to restore. However, a better method would be to tarball your system to DVD. It provides much more protection. Excluding /home, /tmp, and parts of /var, it should fit on one or two disks.

If you happen to have a reference system, you could also take advantage of chmod's --reference=rfile option to fix things.
Top
timeBandit
Bodhisattva
Bodhisattva
User avatar
Posts: 2719
Joined: Fri Dec 31, 2004 1:54 am
Location: here, there or in transit

  • Quote

Post by timeBandit » Thu Dec 14, 2006 7:29 pm

http://forums.gentoo.org/viewtopic-t-41 ... d+777.html
Forum search, lame though it may be, is still your friend....
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Top
mephx
n00b
n00b
Posts: 11
Joined: Thu Nov 23, 2006 7:14 am
Contact:
Contact mephx
Website

  • Quote

Post by mephx » Fri Dec 15, 2006 5:39 am

chris.c.hogan wrote:If you happen to have a reference system, you could also take advantage of chmod's --reference=rfile option to fix things.
this sounds interesting...
but, how do i generate that rfile? :S

thanks everyone
~x
Top
kallamej
Administrator
Administrator
User avatar
Posts: 4993
Joined: Fri Jun 27, 2003 10:05 am
Location: Gothenburg, Sweden

  • Quote

Post by kallamej » Fri Dec 15, 2006 9:45 am

Merged [post]3782519[/post] and onwards to this thread.
Please read our FAQ Forum, it answers many of your questions.
irc: #gentoo-forums on irc.libera.chat
Top
mephx
n00b
n00b
Posts: 11
Joined: Thu Nov 23, 2006 7:14 am
Contact:
Contact mephx
Website

  • Quote

Post by mephx » Thu Dec 21, 2006 8:50 pm

anyone? :oops:
Top
timeBandit
Bodhisattva
Bodhisattva
User avatar
Posts: 2719
Joined: Fri Dec 31, 2004 1:54 am
Location: here, there or in transit

  • Quote

Post by timeBandit » Thu Dec 21, 2006 9:28 pm

Sorry, thought the person who posted that would reply.

The "rfile" mentioned isn't a generated file--I assume you were hoping it was a file listing all the correct permissions to apply. It's not. What chmod --reference=fileA fileB does is set the mode (permissions) of fileB to be the same as that of fileA (the reference file).
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Top
Yura
n00b
n00b
User avatar
Posts: 10
Joined: Sun Feb 25, 2007 12:43 pm

suid bit lost for /usr

  • Quote

Post by Yura » Wed Jan 14, 2009 9:08 am

i was installing gentoo (openoffice) when free disk space ended... I decided move /usr directory to other partition (it was at root) i execute cp -r /usr /mnt/r/

(/mnt/r - ext3 partition) in /etc/fstab i wrote:
/mnt/r/usr auto bind 0 0

old /usr i deleted.

boot gone successfully.

but when i logined as user and typed startx it wasn't execute;
i looked at /usr/sbin and saw that no files had SUID bit.

for some files i set it manually. but it's to hard to set it for all files. reinstall all in /usr because 1 bit is very long and pity.

1. Have somebody any ideas ?
2. and why suid bit was lose when copies with cp ?
Top
eccerr0r
Watchman
Watchman
Posts: 10239
Joined: Thu Jul 01, 2004 6:51 pm
Location: almost Mile High in the USA
Contact:
Contact eccerr0r
Website

  • Quote

Post by eccerr0r » Thu Jan 15, 2009 2:07 am

For #2 - You'll need to cp with -p to copy/retain permissions and owners.
As for #1, I'm not sure if there's a record of suid bits anywhere... this might be a good feature to add to portage? Not sure...
Intel Core i7 2700K/Radeon Firepro W2100/24GB DDR3/800GB SSD
What am I supposed watching?
Top
timeBandit
Bodhisattva
Bodhisattva
User avatar
Posts: 2719
Joined: Fri Dec 31, 2004 1:54 am
Location: here, there or in transit

  • Quote

Post by timeBandit » Thu Jan 15, 2009 2:32 am

Merged above two posts here since it amounts to the same problem. Unfortunately, as pointed out above it's necessary to re-merge everything to be sure it's all fixed.
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Top
eccerr0r
Watchman
Watchman
Posts: 10239
Joined: Thu Jul 01, 2004 6:51 pm
Location: almost Mile High in the USA
Contact:
Contact eccerr0r
Website

  • Quote

Post by eccerr0r » Thu Jan 15, 2009 4:30 pm

I think portage, after every file is cataloged (it does MD5 everything?), also record group/owner and file modes. I don't think these really are quite as helpful as the md5, but can help in situations like these as it appears people screw this up more often than one would think.
Intel Core i7 2700K/Radeon Firepro W2100/24GB DDR3/800GB SSD
What am I supposed watching?
Top
Post Reply

22 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic