Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of the difference between chown and chmod commands in Linux

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In linux systems, both chmod and chown commands can set permissions, but they are also different; chmod is used to set permissions for folders and files, such as files in our system that cannot be read or written, and need to be used to set permissions of 777. while chown is used to set user groups, such as authorizing a user group to facilitate user rights control.

The two commands we want to share today are also commonly used. Chmod and chown seem to be similar in spelling, but they are used for different purposes. Chmod is used to set folder and file permissions. For example, files cannot be read or written in VPS hosts and need to be used to set 777permissions, while chown is used to set user groups, such as authorizing a user group, to facilitate user permissions control.

Specific use we use examples to solve, those so-called various parameter commands I do not like to share, because usually do not need, directly use practical.

First, permission to use: all users

Usage: chmod [- cfvR] [--help] [--version] mode file...

Description: the file access authority of Linux/Unix is divided into three levels: file owner, group and others. Chmod can be used to control how files are accessed by others.

Mode: permission setting string, in the following format: [ugoa...] [[+-=] [rwxX]...] [,...], where u indicates the owner of the file, g indicates that the owner belongs to the same group (group) as the owner of the file, o indicates other people, and an indicates all three.

+ means to increase permissions,-to cancel permissions, and = to set permissions uniquely. R indicates readable, w indicates writable, x indicates executable, and X indicates only if the file is a subdirectory or if the file has been set to executable. -c: show the change action only if the file permission has indeed been changed-f: do not display an error message if the file permission cannot be changed-v: display the details of the permission change-R: make the same permission change for all files and subdirectories in the current directory (that is, one by one by recursion)-- help: show auxiliary instructions-- version: display version

For example: chmod-R 777 / www/itbulu.com/wp-content/*

Represents to set all files under the above folder to be readable and writable, or so.

Cd wp-contentchmod-R 777 *

Second, instruction name: chown

Permission: root

Usage: chown [- cfhvR] [--help] [--version] user [: group] file...

Description: Linux/Unix is a multi-person multi-work system, all files have owners. With chown, the owner of the file can be changed. Generally speaking, this directive is only used by the system administrator (root). The average user does not have the permission to change someone else's file owner, nor does he have the permission to change his own file owner to someone else. Only the system administrator (root) has such permissions.

User: new file owner user IDgroup: new file owner user group (group)-c or-change: function similar to-v, but only return modified parts-f or-quiet or-silent: do not show error message-h or-no-dereference: make changes only to symbolic linked files, but not to any other related files-R or-recursive: recursive processing Process all files and subdirectories under the specified directory together-v or-verbose: show instruction execution-dereference: function is opposite to-h-help: display online instructions-reference=: sets the owner of the specified file or directory with the group to which it belongs-version: displays version information

Chown-R www:www / home/wwwroot/*

Explanation:-R recursively handles all files and folders, with the first www representing the owner name of the file and the second www representing the group name to which it belongs.

The difference between chown and chmod commands

Chown modifies the user and user group properties of files and folders

1. To modify the owner of the file hh.c. It is owned by the user who changed it to codetc.

Chown codetc hh.c

This applies the user access of hh.c to codetc as the owner

2. Change the owner and group of the directory / tmp/sco to codetc and group net

Chown-R codetc:net / tmp/sco

Chmod modifies read-write execution properties of files and folders

1. Modify the hh.c file to be writable, readable and executable

Chmod 777 hh.c

To modify all file attributes in a directory to be writable, readable and executable

Chmod 777 *. *

Replace the folder name and suffix name with *.

By the same token, if you want to modify the properties of all htm files

Chmod 777 * .htm

2. Modify the directory / tmp/sco to be writable, readable and executable

Chmod 777 / tmp/sco

To modify all folder properties under a directory to be writable, readable and executable

Chmod 777 *

Just replace the folder name with *.

To modify the properties of all files and folders and their subfolders under / tmp/sco to be writable, readable and executable

Chmod-R 777 / tmp/sco

Writable wish4

Readable riter2

Executable xroom1

777 is full access. You can freely combine the permissions of users and groups as needed

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report