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 changes the user and/or group ownership of for given file. The syntax is:

chown command

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 test user and list the permissions, run:

# chown test demo.txt

# ls -l demo.txt

Sample outputs:

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

In this next example, the owner is set to test followed by a colon and a group onwership is also set to test group, run:

# chown test: test demo.txt

# ls -l demo.txt

Sample outputs:

-rw-r–r– 1 test test 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 test 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 /user1 to “root”, execute:

# chown root /user1

Likewise, but also change its group to “httpd”, enter:

# chown root:httpd / user1

Change the owner of /user1 and subfiles to “root”, run:

# chown -R root /u

Leave a Reply

Your email address will not be published. Required fields are marked *