LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-10-2020, 12:58 PM   #1
ckumar
LQ Newbie
 
Registered: Dec 2020
Posts: 1

Rep: Reputation: Disabled
New to Linux - chown not worked as per expectation


below is the snapshot of the code in production , requirement was to change the user and owner for one of the directory "policy"

i added $chown -R ${USER}:${USER} /opt/app/policy just below the existing code in prod which is $chown -R root:${USER} /opt/app.
now it lookis like

chown -R root:${USER} /opt/app
chown -R ${USER}:${USER} /opt/app/policy


but after running script the "policy" directy dont have the user changed it still shows root.
 
Old 12-10-2020, 01:23 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by ckumar View Post
below is the snapshot of the code in production , requirement was to change the user and owner for one of the directory "policy"

i added $chown -R ${USER}:${USER} /opt/app/policy just below the existing code in prod which is $chown -R root:${USER} /opt/app.
now it lookis like

chown -R root:${USER} /opt/app
chown -R ${USER}:${USER} /opt/app/policy


but after running script the "policy" directy dont have the user changed it still shows root.
Welcome to LQ,

There could be a couple of problems here. The group for root owned files, probably should remain as root. If the directory above is owned by root and also if the files are currently owned by root then you would need to have root privileges to be able to change ownership, either by logging in as root or using the sudo command.

I'd recommend issuing these on the command line to get it working correctly and then copying that into your script to test it out further. You also can enable verbose and debug output within your script by adding a "set -xv" line near the top of your script, I'm not sure that debug output will get you much, but it's worth trying out. You also can echo what $USER is and determine if that is also a group name on the system.

Not sure it is a right choice to change ownership of a directory of files in the general area that is not related specifically to a user's home location.
 
2 members found this post helpful.
Old 12-10-2020, 01:24 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
You post is not understandable.

Let me ask you a question. If something is owned by root, what kind of permissions would you need to have to change it?

For example, this file
Code:
ls -l /usr/bin/dillo
-rwxr-xr-x 1 root root 899896 Jul  7 16:31 /usr/bin/dillo
That says that root can read/write/execute. No one else can write to it.

See:
man chown
man su
man sudo
man ls

Or do I misunderstand something?
 
Old 12-10-2020, 01:33 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by ckumar View Post
but after running script the "policy" directy dont have the user changed it still shows root.
Probably your system protecting you from shooting yourself in the foot.

Maybe chown has a verbose switch, what does it say?

Anyhow, "ckumar"? Sounds familiar, I think TB0ne will be along shortly...
 
Old 12-10-2020, 04:09 PM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ckumar View Post

chown -R root:${USER} /opt/app
chown -R ${USER}:${USER} /opt/app/policy

but after running script the "policy" directy dont have the user changed it still shows root.
The commands by themselves, if executed by the superuser, will change ownership of all directories and files at /opt/app/policy to $USER.

Note that there are several conditions for this to work. Here are a few:

Are you sure these lines are executed at all? If so, how do you know?
Only the superuser can change ownership. Are the commands executed by root? Again, how do you know?
Are you sure the value of USER is something else than "root"?

And of course, are there any error messages?

A few troubleshooting tips:
Add echo commands before and after the chown commands.
Use set -x before the commands you want to troubleshoot, and set +x after them (this works for Bash, not sure for other shells).

Last edited by berndbausch; 12-10-2020 at 06:50 PM.
 
  


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
Slackware 14.1, full install, sound card worked OK, but microphone is not worked. zw963 Slackware 7 11-23-2013 06:57 AM
PHP5 - chown() - Warning: chown(): Operation not permitted pizzipie Programming 11 09-10-2013 03:53 AM
Expectation from a 2yr experienced professional antriksh Linux - General 5 02-11-2013 07:53 AM
SQUID - connection limit per user not per IP adress iksik Linux - Software 3 03-10-2010 09:52 AM

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

All times are GMT -5. The time now is 09:01 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