How To Use chmod and chown Command

by on October 11, 2006 · 24 comments· LAST UPDATED August 31, 2012

in

How do I use chmod and chown command under Linux / Unix operating systems?

Use the chown command to change file owner and group information. Use the chmod command to change file access permissions such as read, write, and access.

chown command

chown command changes the user and/or group ownership of for given file. The syntax is:

 
chown owner-user file
chown owner-user:owner-group file
chown owner-user:owner-group directory
chown options owner-user:owner-group file
 

Examples

First, list permissions for demo.txt, enter:
# ls -l demo.txt
Sample outputs:

-rw-r--r-- 1 root root 0 Aug 31 05:48 demo.txt

In this example change file ownership to vivek user and list the permissions, run:
# chown vivek demo.txt
# ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 vivek root 0 Aug 31 05:48 demo.txt

In this next example, the owner is set to vivek followed by a colon and a group onwership is also set to vivek group, run:
# chown vivek:vivek demo.txt
# ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 vivek vivek 0 Aug 31 05:48 demo.txt

In this example, change only the group of file. To do so, the colon and following GROUP-name ftp are given, but the owner is omitted, only the group of the files is changed:
# chown :ftp demo.txt
# ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 vivek ftp 0 Aug 31 05:48 demo.txt

Please note that if only a colon is given, or if NEW-OWNER is empty, neither the owner nor the group is changed:
# chown : demo.txt
In this example, change the owner of /foo to "root", execute:
# chown root /foo
Likewise, but also change its group to "httpd", enter:
# chown root:httpd /foo
Change the owner of /foo and subfiles to "root", run:
# chown -R root /u
Where,

  • -R - Recursively change ownership of directories and their contents.

chmod command

The information about the chmod command is covered in our previous tutorial - "how to use change user rights using chomod command".

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 24 comments… read them below or add one }

1 E. Hill October 29, 2006 at 2:59 pm

Excellent site!! Your explanations are great. Clear and concise and very helpful! Thanks!

Reply

2 somery.van May 15, 2008 at 7:53 am

it so good but the result it not enough so i want you add more information.
thank you

Reply

3 Derrick July 1, 2009 at 7:53 pm

don’t know where you got this but all you get is an error that the directory does not exist. so if this script is working for you, then your server is set up wrong and you are riding or borrowed time.

Reply

4 Derrick November 13, 2009 at 6:39 am

doesn’t work

Reply

5 ubi January 14, 2010 at 6:10 am

nice lesson =)

Reply

6 sabaresh October 18, 2010 at 8:54 am

its a good one for the ones who use linux for the first time…..can read and learn

Reply

7 SilverBear May 15, 2011 at 4:46 pm

Good lesson as far as it goes. However:
This command will only work if the file targeted by the command exists. You can’t change ownership of a non-existent file!

Reply

8 Hitesh March 15, 2012 at 1:10 pm

Hello,

I am Hitesh, i am a S/W Engineer, My nickname is CSD.
Linux is useless operating system.

I am the owner of Tata Magic IRIS. I don’t need this command to change anything.
I am the ROOT.

You all people are FOOL.

Reply

9 NoNeedForAName April 2, 2012 at 1:56 am

Hello,

I am Hitesh, i am ID10T who uses everybody’s valuable oxygen.
Intelligence is useless concept me.

I am the owner of pathetic little car. I don’t have anything contribute to site.
I am the MORON.

You all people are TOOL.

In other words: if you don’t understand proper english, don’t try to act like you do, you little numpty.

Reply

10 Kc5jmr April 13, 2012 at 2:40 am

What if I want to give permission to everyone
/home/storage
I need it so anyone who access from a windows share via network neighborhood can read and write to this directory from any location

Robert

Reply

11 SilverBear April 15, 2012 at 7:01 pm

Hi, Kc5jmr.
The chmod and chown commands are really for use to fine-tune permissions among users of a single filesystem [–usually, but not always, a single computer with multiple users.].

What you’re talking about is setting up a Samba [SMB] fileserver for network sharing of files. That is really a whole different project from just adjusting file permissions for various logged-in users on the same machine!

I use Samba to access files on my desktop workhorse from my portable computer. Setting up a Samba server and writing a config file that specifies the directories to be shared is not all that difficult.

BUT SMB was a Windows protocol devised in the middle 1980’s. To the best of my understanding, Windows 7 uses some other setup. All I know is that my Win7 OS on my portable can’t connect to my Linux samba server, but booting the same machine in Mepis Linux allows me full access. Since I only boot into Win7 to play “Sid Meyer’s Civilization” [versions IV & V] the lack of backward compatibility to SMB/Samba really doesn’t affect me enough for me to bother to try to get Win7 to play nice. I do all my serious work in Linux, and only have so much time/energy for gratuitous MS-Windows troubleshooting!

Reply

12 Newbie May 9, 2012 at 4:27 pm

Great website i found the solution for many of my problems here :) Wish you luck and success !

Reply

13 Alan T June 29, 2012 at 1:57 am

Hitesh, don’t comment here you obviously no nothing about system administration.

And if your using a development system\environment that “requires” a root account so your can write software your the FOOL.

Reply

14 LinuxUsers June 29, 2012 at 1:20 pm

Hi all,

Please stop feeding the troll that is Hitesh.

Sincerely,

Real Linux and FOSS users.

Reply

15 Mac October 25, 2012 at 10:28 am

Hi Guys

can anyone assist, i am getting an error when trying to start one of my applications on my linux server.

./pwcallmgr: error while loading shared libraries: libjs.so: cannot restore segment prot after reloc: Permission denied

Reply

16 Hilary November 19, 2012 at 4:48 pm

you have over written the permissions because these instructions were poorly written open up your Terminal navigate tothe root file system and add yourself as a user allowed to open this file… having followed these instructions with teh recursive you have possibly told your OS that only root can open that file when you need to be the one who does. use grep to find the for or just type in find ./pwcallmgr once you have this file chown yourusername ./pwcallmgr if it says not permitted the sudo chown yourusername ./pwcallmgr should do it.

Be very careful when using the -Recursive switch or you could end up having to boot using a live disk to fix this …. and make your computer unbootable…
You can also use Chmod 777 if you need to however you should check what file permissions that file is supposed to have.

Of course if you have a full back up on another drive of your .hidden files and your home file along with any other files you like to keep then it can be faster just to reinstall with the latest OS…. but I would back things up just in case and try the chown first ….

Reply

17 Udayjeet The Fututre Coder January 14, 2013 at 6:29 am

Thanks, as i always prefer this website in the case of unix commands or scripts.

Thanks to this website.

As i get the 100% correct solutions.

Reply

18 Udayjeet The Future Coder January 14, 2013 at 6:30 am

sorry the name gone wrong ………..oops

Udayjeet “THE FUTURE CODER”

Reply

19 marty March 3, 2013 at 6:38 am

“chown -R” frightens me. When I’m admin’ing I’m often needed to change the ownership of files owned by “bob” to “bill” in filesystems with files owned by a number of accounts.

I would typically (from memory):

find . -user bob -exec chown bill {} \;

Reply

20 cheran August 13, 2013 at 12:48 pm

excellent stuff bro .. did my job .. so user friendly .. keep it up

Reply

21 Elias November 9, 2013 at 1:05 pm

How to change d05 directory ownership from root to oracle

Reply

22 biscuit November 29, 2013 at 4:21 am

chown -R oracle:oracle d05 (path to d05 directory)

Reply

23 l0xy July 23, 2014 at 6:03 pm

Hello. At the last line of this guide where you have “/u” did you possibly mean “/foo” ??
To be consistent, perhaps this is what you rather meant?

Reply

24 Pradeep November 7, 2014 at 12:16 pm

I have directory ‘/u02/Infa_shared’, created one group ‘Developers’ and Added users ‘A’,’B’. Owner of this directory is ‘infaadmin’ and user belongs to ‘admin’ group.

How can I give read, write, execute access on this directory to ‘Developers’ by keeping ‘admin’ group has its owner in Linux?

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: