LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   I did chown -R root:root /usr - did I screw it up? (http://www.linuxquestions.org/questions/slackware-14/i-did-chown-r-root-root-usr-did-i-screw-it-up-4175435933/)

Lennie 11-06-2012 01:10 PM

I did chown -R root:root /usr - did I screw it up?
 
I just realized I have installed some packages where I was the owner of all files and folders, and now I am the owner of those folders in the system. So I tried to fix it by just chown one directory at a time to root:root, started with /usr. After I did that I realized there might have been files that should not have root as both owner and group-owner... Is there a way to find out and fix this?

MensaWater 11-06-2012 01:20 PM

Yes you screwed it up.

Bad hackers sometimes try to set permissions on everything so it is globally accessible. Due to this many secure programs actually expect a certain level of permission/ownership/group and if they don't have it will fail on the theory you've been hacked.

How to fix it depends on your distro. Many of the package managers include information about what permissions/ownership/groups files within the package should have after installation.

Lennie 11-06-2012 01:35 PM

Is it possible to fix it if I reinstall all packages from the official repository? Is there a way to do that in one command? Or mount the iso and install those groups of packages I chosed during installation?

Which is the easiest way to fix this, or should I just reinstall from scratch?

Lennie 11-06-2012 01:53 PM

I'm not sure exactly which packages I have installed that I have build myself. I try to remember to save them if I need to reinstall, but I have forgotten some. Is there a way to check /var/log/packages/ and find which of those does not exist in the official repository? I miss a log-file that says what packages I have installed/upgraded/removed, and at what date... (Comming from Arch, I just loved Pacman...)

ponce 11-06-2012 01:59 PM

"slackpkg clean-system" will prompt you for removing your added packages (if you don't have upgraded anything provided with slackware), obviously this is only for you to have a list, not for actually removing them (I don't think you want that).
you should also use the TAG variable when building your packages (use the BUILD one when rebuilding the official slackware packages), so that they are named ...lennie, for example, and you can do a "ls -la /var/log/packages/*lennie" and see your modifications.
the log you're looking for is the folder /var/log/packages (and /var/log/scripts too).

Quote:

Which is the easiest way to fix this, or should I just reinstall from scratch?
the last thing you said

Mark Pettit 11-06-2012 02:22 PM

Confucius say : man who play in root, kill tree !


(don't feel bad - we've all done it at some stage :-)

Lennie 11-06-2012 02:57 PM

I have a vague memory that I have seen other threads with similar titles, and that I used to think "How can one even think of doing such a stupid thing..." I can't understand I did this... Just laughing at it now...

So it's easier to reinstall the whole system from scratch, than try to fix it by forcing it to reinstall all packages? Shouldn't that set ownership right? *hoping someone gives another answer* But if I backup my /home and save those unofficial packages that have the right ownership, then it shouldn't be too much work to start over again.

Okay, tomorrow... Now I'm to tired. I guess I shouldn't do anything more as root now. (I can't do anything with sudo, but su still works...) And I guess I should be careful what I'm doing as user with my /home, and my Data-partition...

Didier Spaier 11-06-2012 05:24 PM

1 Attachment(s)
The code snippet below is stolen to the SeTconfig script in Slackware's installer:
Code:

# These next lines are intended to clean up any permissions
# problems that could be caused by a bad package.  We don't
# intend to make any bad packages here, but it never hurts
# to be safe. :^)
( cd $T_PX ; chmod 755 ./ )
( cd $T_PX ; chmod 755 ./var )
if [ -d $T_PX/usr/src/linux ]; then
  chmod 755 $T_PX/usr/src/linux
fi
if [ ! -d $T_PX/proc ]; then
  mkdir $T_PX/proc
  chown root.root $T_PX/proc
fi
if [ ! -d $T_PX/sys ]; then
  mkdir $T_PX/sys
  chown root.root $T_PX/sys
fi
chmod 1777 $T_PX/tmp
if [ ! -d $T_PX/var/spool/mail ]; then
  mkdir -p $T_PX/var/spool/mail
  chmod 755 $T_PX/var/spool
  chown root.mail $T_PX/var/spool/mail
  chmod 1777 $T_PX/var/spool/mail
fi

In this code snippet '$T_PX' stands for /mnt which will be the root of the new Slackware distribution.

So my guess (only a guess) is if you run the 'chmod' commands with $T_PX="" you will get back the standard Slackware permissions.

This does not solve the ownership problem but I believe that
in /usr almost everything is owned by root.root. <standard disclaimer here>.

EDIT On an almost vanilla full Slackware 14 installation:
Code:

find /usr -not -user root -or -not -group root|xargs ls -l>not_root.txt
output attached file.

titopoquito 11-07-2012 04:08 AM

http://slackware.org.uk/people/alien...om_manifest.sh

I didn't try it myself, but this script was mentioned several times before on similar occasions. It shoul be able to restore your permissions from the Manifest file that is found on the Slackware CD/DVD.

688a 11-07-2012 08:52 AM

Just come across a question which is, when I install a library or application, I will do it as a root. Is that a right way to install a new thing?

Didier Spaier 11-07-2012 10:20 AM

You must do that as root if you install it in the intended places, e.g. /usr/bin for binaries, as theses directories are writable only by root. If you install it in some non standard place like your home instead you can do that as a regular user depending on the ownership/permissions of that place but:
(1) some additional steps are required in that case to have the binaries or the libraries accessible.
(2) this is generally not recommended as it makes maintenance of applications and libraries problematic.

So, just use the packages management tools included in Slackware for installation and do that as root.

If asking the question you had that in mind: yes, generally speaking there is a risk in issuing a command as root, that's why you should only install packages from a trusted source: primarily packages included in the Slackware Linux distribution itself, then packages provided by one of the main Slackware contributors and packages you make yourself using a SlackBuild provided by one of the aforementioned sources or by http://slackbuilds.org.

And avoid as much as you can to install packages whose source code is not available, for safety concerns.

Lennie 11-07-2012 11:31 AM

Thank you all who tried to help me. I ended up reinstalling, it was actually the easiest and quickest way to get up and running again. Lesson learned - I hope...

688a 11-07-2012 10:51 PM

Quote:

Originally Posted by Didier Spaier (Post 4824170)
You must do that as root if you install it in the intended places, e.g. /usr/bin for binaries, as theses directories are writable only by root. If you install it in some non standard place like your home instead you can do that as a regular user depending on the ownership/permissions of that place but:
(1) some additional steps are required in that case to have the binaries or the libraries accessible.
(2) this is generally not recommended as it makes maintenance of applications and libraries problematic.
...

THANK YOU :hattip:

MensaWater 11-08-2012 09:34 AM

Quote:

Originally Posted by Lennie (Post 4824264)
Thank you all who tried to help me. I ended up reinstalling, it was actually the easiest and quickest way to get up and running again. Lesson learned - I hope...

Yep. There are two types of Administrator. Those that have screwed their systems up at least once and those that lie and say they never have.

Beware "rm -rf *".

:jawa:


All times are GMT -5. The time now is 03:40 AM.