Chown command on Linux (change property)
The chown command in Linux changes the owner of the file and can also change the group to which this file belongs.
For most permission issues, users who are new to Linux tend to change file permissions with the command Chmod. But generally, changing ownership of the parent directory or of a file is sufficient. Then link to this post.
The chown command allows the following options:
- -v: Reports the owner of the files, including changes of owner;
- -c: Reports only the change of owner;
- -R: Change the owner of all files and directories recursively within the same hierarchy.
The chown command can take as a parameter:
Login
If only the user login is entered, the ownership of the File Owner changes, but the group ownership remains unchanged.
Login:group
If a “login**:** group” or “login” is entered**.** group”, both the ownership of the file owner and the group are changed.
Login:
If a “login**:” or “login” is entered.** “without informing the group, the owner of the file is changed, and the group is changed to the group in which the specified login is part.
:group
If ”: group” or “is entered**.** group” without entering the login, chown will act like the chgrp command, changing only the file group.
Examples:
Changes the owner of the Leiame.txt file for the uira user:
Changes the owner of the Leiame.txt file for the user uira and the file group for the user group:
Leiame.txt Changes the owner of the Leiame.txt file for the user uira and the group for users:
Changes the file group to users and leaves the file owner unchanged:
Changes the owner of all files and directories inside /home/uira to the user uira:
An ordinary user can only pass ownership of files and directories that they own. The root user can change ownership of any file or directory.
Most of the time, it is not necessary to change the permissions of a directory to “777” as a way of granting permissions for a program to be able to access it. Just check with the “ps -aux” command which user is running the program, and change the owner of the directory or file, or of the group.
Take PHP for example:
In this example, the user running php-fpm is Apache.
So, to allow php to write something to the upload directory, it is not necessary to change the permission, but the owner of the directory:
The owner of the upload directory is then changed to the Apache user. This way, the php-fpm process will be able to write, read, and access the upload directory:
Are you an IT professional, support professional, or developer, have you ever considered learning Linux for real?
Is it still bad to get an LPI Linux Essentials certification from breaking?
And even better, with the best online course for Linux?
[RICH_REVIEWS_SHOW CATEGORY=“Course” num=“all “]
Do like these people and create your account now.
Here you have everything you need to succeed in the LPI and CompTIA exams
- Practical Classes at Shell
- Flashcards for memorization
- Crossword Games
- 06 virtual servers on Amazon just for you
- Mind Maps
- Video Glossary
- Preparatory simulation for the exams
- Personalized class schedule
- Guided exercises — Real Laboratories
- Lesson Resources (notes and others)
Do you want to know if a certification is worthwhile? Learn why salaries are good, and why companies are looking for Linux professionals.
You’ll understand that the benefits far outweigh the sacrifice.
And if you’ve made up your mind, check out our Certification Guide.
And if you want to know where to take the tests, check the list of cities.
If you want to know the language of the exams, check out this post.
Learn much more about Linux in our online course. You can register here. If you already have an account, you can log in here.