LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-09-2021, 04:29 AM   #1
nselx
LQ Newbie
 
Registered: Feb 2021
Posts: 23

Rep: Reputation: 0
Ownership changed from root to user :<


I've got some problems and to get them fixed, I changed the ownership on /usr from root to user. So many errors thrown afterward, while opening the VBs and basically could not login to root anymore! So the question is that how to get the ownership of /usr back to original, meaning from user's ownership to root ownership. Cause I run sudo -i and I get the operation is not permitted.

Have run the following command before the disaster!
chown -R USER /usr

Last edited by nselx; 02-09-2021 at 04:30 AM.
 
Old 02-09-2021, 04:40 AM   #2
captain_sensible
Member
 
Registered: Apr 2010
Posts: 352

Rep: Reputation: 145Reputation: 145
if i look at my /usr i see owner and group are root:root

so i think the basics are you need to have /usr being owned by user "root" and group "root"

if you change directory to /, it going to be along the lines of:
Code:
# chown root:root usr -R
or if on debian maybe

sudo chown root:root usr -R

basic syntax is :

chown [command] which owner and group do you want to chnage it to root:root -R permission recursive
 
Old 02-09-2021, 05:35 AM   #3
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,569

Rep: Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499
Which distribution of Linux are you using? Did you have a separate root user which you created a password for or did you use sudo when logged in as your primary user?

Quote:
I've got some problems and to get them fixed, I changed the ownership on /usr from root to user.
Highly unlikely that would resolve whatever problems you had.
 
Old 02-09-2021, 05:44 AM   #4
lvm_
Member
 
Registered: Jul 2020
Posts: 983

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
It's not that easy, the biggest issue is the suid/sgid bit which gets reset whenever owner is changed. The upshot of this is that even though you restore the owner to root:root, sudo or other commands relying on suid still won't work. Also not all files in /usr are owned by root:root, some are owned by root but have a different group - and this may break programs using these files and running under a non-root account. You are screwed big time. While theoretically there is nothing difficult in restoring corrupted access rights and SCO Unix even had such an utility called fixmog, I don't know of linux equivalent. Reinstall or install the same distro with the same packages, tar /usr, boot from live CD and extract it over your current /usr - tar preserves suid.
 
2 members found this post helpful.
Old 02-09-2021, 05:54 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,681
Blog Entries: 19

Rep: Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492Reputation: 4492
A lot of newbies get caught that way. It's one of the few problems that really need a reinstall. The bonus is that you won't do it again!

The problem is that people coming over from Windows don't immediately understand what file ownership and protections are for. They just seem like a nuisance, getting in the way of something you want to do, so changing them seems like a good solution. As lvm has pointed out, they are baked into the core of all Unix operating systems and should not be altered unless you know exactly what the consequences will be. If you need to manipulate those files, do it as root.
 
Old 02-09-2021, 07:33 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
If this is an RPM-based distribution, try as root
Code:
rpm --restore $(rpm -qa)
This will restore owner, group, permissions and capabilities of all files installed via package management system to the states they were in at the installation time.

For a DEB-based system, you may try something like
Code:
dpkg -S /usr/ | sed 's|: /usr$||' | xargs -d, apt reinstall

Last edited by shruggy; 02-09-2021 at 07:53 AM.
 
Old 02-09-2021, 08:07 AM   #7
nselx
LQ Newbie
 
Registered: Feb 2021
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lvm_ View Post
It's not that easy, the biggest issue is the suid/sgid bit which gets reset whenever owner is changed. The upshot of this is that even though you restore the owner to root:root, sudo or other commands relying on suid still won't work. Also not all files in /usr are owned by root:root, some are owned by root but have a different group - and this may break programs using these files and running under a non-root account. You are screwed big time. While theoretically there is nothing difficult in restoring corrupted access rights and SCO Unix even had such an utility called fixmog, I don't know of linux equivalent. Reinstall or install the same distro with the same packages, tar /usr, boot from live CD and extract it over your current /usr - tar preserves suid.
As you mentioned It was not that simple. To change back the ownership to root of the directory /usr was unsuccessful.
As I mentioned the operation was not permitted. So I was not even able to login to as a regular user so I had ought to do change thing on boot which I am not that much knowledgeable yet. SO you could guess I lost every info on my system, luckily had backup at some point but all rhcsa's resources for the exam is gone!
I installed Mint again which took me only 10 mins which is worth to skip that painful process of recovery. I got my lesson to not ever again change the ownership of root . That will ruin every program’s structure on my OS.

Last edited by nselx; 02-09-2021 at 08:19 AM.
 
Old 02-09-2021, 08:08 AM   #8
nselx
LQ Newbie
 
Registered: Feb 2021
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lvm_ View Post
It's not that easy, the biggest issue is the suid/sgid bit which gets reset whenever owner is changed. The upshot of this is that even though you restore the owner to root:root, sudo or other commands relying on suid still won't work. Also not all files in /usr are owned by root:root, some are owned by root but have a different group - and this may break programs using these files and running under a non-root account. You are screwed big time. While theoretically there is nothing difficult in restoring corrupted access rights and SCO Unix even had such an utility called fixmog, I don't know of linux equivalent. Reinstall or install the same distro with the same packages, tar /usr, boot from live CD and extract it over your current /usr - tar preserves suid.
As you mentioned It was not that simple. To change back the ownership to root of the directory /usr was unsuccessful.
As I mentioned the operation was not permitted. So I was not even able to login to as a regular user so I had ought to do change thing on boot which I am not that much knowledgeable yet. SO you could guess I lost every info on my system, luckily had backup at some point, but all rhcsa's resources for the exam is gone!
I installed Mint again which took me only 10 mins which is worth to skip that painful process of recovery. I got my lesson to not ever again change the ownership of root . That will ruin every program’s structure on OS.

Last edited by nselx; 02-09-2021 at 08:18 AM.
 
Old 02-09-2021, 08:40 AM   #9
nselx
LQ Newbie
 
Registered: Feb 2021
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by hazel View Post
A lot of newbies get caught that way. It's one of the few problems that really need a reinstall. The bonus is that you won't do it again!

The problem is that people coming over from Windows don't immediately understand what file ownership and protections are for. They just seem like a nuisance, getting in the way of something you want to do, so changing them seems like a good solution. As lvm has pointed out, they are baked into the core of all Unix operating systems and should not be altered unless you know exactly what the consequences will be. If you need to manipulate those files, do it as root.


Thats totally true and I understand your point but as a newbie I would expect a warning on changing those critical settings as it not changing simply and ruins everything. I mean I love this OS, I have removed totally windows to focus on linux and its been couple of months I spend at least 5 hrs a day working on this OS but still a typo can ruin everything. I understand the point that it is a professional OS not for everyone but one should starts from somewhere and to be about to screwed like this needs at least a warning in forehand

Last edited by nselx; 02-09-2021 at 08:45 AM.
 
Old 02-09-2021, 08:43 AM   #10
nselx
LQ Newbie
 
Registered: Feb 2021
Posts: 23

Original Poster
Rep: Reputation: 0
By the way, I have installed Mint and some other programs again. The original problem was not being able to install guest addition on virtual box and I read some post on oracle website to change the permission on the /Virtualbox directory to get the guest addition run on VB. So changing the ownership on parent directory /usr cause that issue.

But the question remain. The ownership feature of thumb rule which inherits from parent directory to child directory how could it be resolved? Is that only root ownership which should not be touched?
 
Old 02-09-2021, 08:47 AM   #11
nselx
LQ Newbie
 
Registered: Feb 2021
Posts: 23

Original Poster
Rep: Reputation: 0
Cool

Quote:
Originally Posted by shruggy View Post
If this is an RPM-based distribution, try as root
Code:
rpm --restore $(rpm -qa)
This will restore owner, group, permissions and capabilities of all files installed via package management system to the states they were in at the installation time.

For a DEB-based system, you may try something like
Code:
dpkg -S /usr/ | sed 's|: /usr$||' | xargs -d, apt reinstall

I will save this for next time, since I reinstall Mint again.
 
Old 02-09-2021, 09:03 AM   #12
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by nselx View Post
The original problem was not being able to install guest addition on virtual box.
How have you tried to install it? Packages virtualbox-guest-utils and virtualbox-guest-x11 should be in Ubuntu repositories Linux Mint uses.

Last edited by shruggy; 02-09-2021 at 09:10 AM.
 
Old 02-09-2021, 09:41 AM   #13
TorC
Member
 
Registered: Dec 2020
Location: as far S and E as I want to go in the U.S.
Distribution: Fossapup64
Posts: 224

Rep: Reputation: 78
Quote:
Originally Posted by nselx View Post
Thats totally true and I understand your point but as a newbie I would expect a warning on changing those critical settings as it not changing simply and ruins everything. . . .

As some User's forum signature says, "Linux assumes the user knows exactly what he/she is doing," as I paraphrase.


Welcome! What you just did is somewhat of an initialization in Linux, as @hazel implies! LOL
 
Old 02-09-2021, 09:58 AM   #14
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
An obligatory quote from The UNIX-HATERS Handbook:
Quote:
Ken Thompson has an automobile which he helped design. Unlike most automobiles, it has neither speedometer, nor gas gauge, nor any of the other numerous idiot lights which plague the modern driver. Rather, if the driver makes a mistake, a giant “?” lights up in the center of the dashboard. “The experienced driver,” says Thompson, “will usually know what’s wrong.”
 
Old 02-09-2021, 03:24 PM   #15
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,832

Rep: Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219
An even more dangerous command is
Code:
chmod -R ... ...
It will treat files and directories in the same way.
Never run it with an absolute 666 or 777!
And it will even follow symbolic links.
Much safer is
Code:
find ... -type f -exec chmod ... {} +
find ... -type d -exec chmod ... {} +
One run for files and one for directories.
And none for symbolic links.
Still you must know what you are doing...

Last edited by MadeInGermany; 02-09-2021 at 03:27 PM.
 
1 members found this post helpful.
  


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
chown of file doesn't changed the ownership permanently when file is in home directory denka Linux - Newbie 7 12-29-2017 09:15 AM
Root ownership vs wheel ownership StupidNewbie Linux - Security 2 08-08-2012 12:52 PM
[SOLVED] Accidentally changed ownership of a port from root to user Handtuch Linux - Security 2 08-20-2011 10:03 AM
ownership of files changed after upgrade Tinkster Slackware 1 12-20-2002 07:34 PM
Maybe a newbie question: ownership changed Cps530 Linux - Security 4 08-19-2002 02:43 PM

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

All times are GMT -5. The time now is 09:56 AM.

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