LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 11-03-2015, 10:21 AM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 106

Rep: Reputation: Disabled
chown not working for changing owner


hi,

iam trying the change the ownership for a file from the user pooja to arun. but not able to achieve that , when am i executing the with pooja as current user. It is working if i execute the same with root as current user.

Solution, im looking for:
need to change the ownership of file aa and folder bb from pooja to arun, when pooja is the current user.


bash-3.2$ whoami
pooja

bash-3.2$ pwd
/home/pooja
bash-3.2$ ls
1 2 3 4 5 aa

bash-3.2$ chown arun aa
chown: changing ownership of `aa': Operation not permitted

bash-3.2$ chown user:arun aa
chown: `user:arun': invalid user

bash-3.2$ mkdir bb

bash-3.2$ chown -R user:arun bb
chown: `user:arun': invalid user

bash-3.2$ chown -c user:arun bb
chown: `user:arun': invalid user

bash-3.2$ chown -v arun bb
chown: changing ownership of `bb': Operation not permitted
failed to change ownership of `bb' to arun

bash-3.2$ chown -v arun a
chown: cannot access `a': No such file or directory
failed to change ownership of `a' to arun
bash-3.2$ chown -v arun aa

chown: changing ownership of `aa': Operation not permitted
failed to change ownership of `aa' to arun

bash-3.2$ chown arun: aa
chown: changing ownership of `aa': Operation not permitted

bash-3.2$ chown arun: bb
chown: changing ownership of `bb': Operation not permitted
 
Old 11-03-2015, 10:28 AM   #2
Demosa
LQ Newbie
 
Registered: Feb 2013
Distribution: Fedora 23
Posts: 13

Rep: Reputation: Disabled
Simple. You cannot change ownership of a file without sudo permissions.

You can change file permissions with chmod, but you cannot change ownership without elevating permissions. It's a security and auditing feature.



EDIT: A few more details as to why. In the old days of UNIX/Linux, when users had a limited amount of space, changing the permissions to 777 and assigning the owner to someone else would let a user have more disk space at the expense of someone else's disk quota. A big deal when you pay by the megabyte for storage. By requiring sudo to change owners, this could be restricted

Last edited by Demosa; 11-03-2015 at 10:37 AM.
 
1 members found this post helpful.
Old 11-03-2015, 11:08 AM   #3
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 17.3 and 18 at present.
Posts: 1,192

Rep: Reputation: 204Reputation: 204Reputation: 204
Even though you own the file, you cannot change the ownership of it to that of someone else.

As you mention, root can do this so you either have to
Code:
$su root
(switch user to root) then issue the command, remembering to switch back to being a normal user afterwards or use sudo as Demosa mentions above.

Play Bonny!

 
Old 11-04-2015, 12:00 PM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,511
Blog Entries: 1

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
You can copy a file as a user (to your /home) and it inherits your creds. You can also delete files from your home that don't have your creds. Otherwise you need elevated permissions as hinted to by the error message.
 
Old 11-04-2015, 01:08 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,475
Blog Entries: 10

Rep: Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639
Quote:
Originally Posted by Demosa View Post
Simple. You cannot change ownership of a file without sudo permissions.

You can change file permissions with chmod, but you cannot change ownership without elevating permissions. It's a security and auditing feature.



EDIT: A few more details as to why. In the old days of UNIX/Linux, when users had a limited amount of space, changing the permissions to 777 and assigning the owner to someone else would let a user have more disk space at the expense of someone else's disk quota. A big deal when you pay by the megabyte for storage. By requiring sudo to change owners, this could be restricted
This I feel is the best suggestion. I do not recommend you fully become root, but instead utilize sudo.

A further point is to observe the group for the file. Many times each individual user has their own named group, typically matching their username. So consider "chgrp" as well.

I very regularly do use things like:
Code:
sudo chown -R new-name top-level-directory-name
sudo chgrp -R new-group-name top-level-directory-name
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Command Line | Change The Owner Of Files And Folders | chown LXer Syndicated Linux News 0 08-20-2011 03:10 PM
chown confuse:which owner is good?moving and editing website from windows to linux. momok Linux - Security 3 06-28-2011 04:14 PM
chown cannot change owner PMP Linux - Newbie 6 07-07-2009 05:56 AM
Changing Owner sghod1212 Mandriva 1 12-19-2005 07:30 PM
CHOWN as root fails; owner 4294967295? eventide Linux - Hardware 1 11-24-2003 01:42 AM


All times are GMT -5. The time now is 01:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration