File Permisions - chown

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,263
Reaction score
2,433
Credits
3,941
The command chown is the chmod's cousin. It is used for changing the ownership rights of a file (hence the name 'chown' - change owner). It does not change the read, write and execution permissions however.

This command, though available to every user, is probably going to be used when you're working as root. The command is uses like this:

Code:
chown owner.group filename

Let's say you want to copy something from your Windows partition (if you have one). You mount the partition (as root) and to save time, you copy the file to your user directory /home/bob/. If you type ls -l the_file you'll get something like this:

Code:
-rw-r--r--  1 root    root          2428 Nov 17 13:18 the_file

As we now know from the previous lesson, root is the owner of the file. Therefore, root is the only one who has write permissions for the file (permission to modify its content). If you plan on working with the file as "bob", there isn't a snowball's chance in hell to modify that file until, as root, you run chown on the file. So let's do it!

Code:
chown bob.bob the_file

This example presupposes that your Linux version creates groups for each user. There are others that will create a generic group called users for everybody who uses the computer. On a network, groups are created according to the needs of the organization. On your single home computer, just type ls -l and see what system corresponds to you.

As you can see, 'chown' is absolutely necessary if you're working as more than one user with the computer.
 


1. I copied 'passwd' file from /etc to home directory using 'cp' command, I have noticed that the ownership (from root to user) is changed. If I want to retain same ownership, how can I do that?

2. for the 'passwd' file I have following permission in my home directory:

-rw-r--r-- 1 rajat rajat 1220 Aug 18 21:43 passwd

Now, I have only changed only group using command: sudo chown rajat.root passwd

-rw-r--r-- 1 rajat root 1220 Aug 18 21:43 passwd

After this, I tried to edit the passwd file from root account and able to do it.

My question is: As per permission, user have read-write permission where as group only have read permission. Then how I am able to edit this file? (I know I am asking silly question but I didn't get any answer anywhere else)
 
make youself a member the wheel group
 
1. I copied 'passwd' file from /etc to home directory using 'cp' command, I have noticed that the ownership (from root to user) is changed. If I want to retain same ownership, how can I do that?

2. for the 'passwd' file I have following permission in my home directory:

-rw-r--r-- 1 rajat rajat 1220 Aug 18 21:43 passwd

Now, I have only changed only group using command: sudo chown rajat.root passwd

-rw-r--r-- 1 rajat root 1220 Aug 18 21:43 passwd

After this, I tried to edit the passwd file from root account and able to do it.

My question is: As per permission, user have read-write permission where as group only have read permission. Then how I am able to edit this file? (I know I am asking silly question but I didn't get any answer anywhere else)

You are able to edit the file, because as root you have access to all files, folders, etc...

To test this, as your normal user create a file, do a chmod 000 to your file. As your normal user, you should not be able to edit the file. Sudo to root and edit the file, you will probably need to write the file with w! (vim) in order for it to save.

Note: sudo, su - and logging in as root should be used sparingly. Do not make a habit of running as root. If you do... you will eventually find out how wrong things can go! o_O

The wheel group doesn't have quite the access that the root user does. Also, in the /etc/sudoers file you can allow root access to users and the wheel group in a granular fashion. Again use with caution and test thoroughly.
 
Last edited:
This thread is nearly a decade old. Perhaps you'd have done better to open a thread - though I do suppose this means you at least used the search function, which is better than many.
 
I think it just shows that even old threads can be helpful. Things that others have learned long ago, needs to be learned by newer users.

I've gotten great info from some older threads. Do a search for shell script math, awk, or how to parse CSV strings into separate variable values. Some of that stuff I found in posts from the '90's. It's ancient, but it's still gold when that's what you're looking for.:)
 
Oh, they can be, but it's best to start your own thread (feel free to reference the original) as the original posters in the thread may be long gone, not interested in notifications, or otherwise disinterested. Plus, odds are that your problem is still a bit unique and worthy of its own thread.

I figure six months, or less in some cases, is a good limit. If the thread's not had any activity in that long, it's probably best to start your own thread. Again, you can trivially reference another thread. "See here for more information that I think relates to my problem..."

Old threads are great - as static stores of knowledge.

An exception might be if things have changed and you want to update/correct the information with new information. In that case, updating old threads is alright by me.
 
1. I copied 'passwd' file from /etc to home directory using 'cp' command, I have noticed that the ownership (from root to user) is changed. If I want to retain same ownership, how can I do that?

2. for the 'passwd' file I have following permission in my home directory:

-rw-r--r-- 1 rajat rajat 1220 Aug 18 21:43 passwd

Now, I have only changed only group using command: sudo chown rajat.root passwd

-rw-r--r-- 1 rajat root 1220 Aug 18 21:43 passwd

After this, I tried to edit the passwd file from root account and able to do it.

My question is: As per permission, user have read-write permission where as group only have read permission. Then how I am able to edit this file? (I know I am asking silly question but I didn't get any answer anywhere else)
Thanks alot but I want to download the app in my software
 

Members online


Top