How we can use the chown recursive command on a Linux server

By Rebecca
16 Min Read
chown recursive

The files and directories on Linux systems all belong to someone. You can change the owner with the chown recursive command. We show you how.

Each file belongs to a user and a group

Linux is a multi-user system. The operating system allows you to define multiple user accounts and for any valid user to log on to the computer. In addition, multiple users can use a single computer at the same time.

To keep a record of which user owns files and for added security, Linux uses the concept of ownership. Each file belongs to an owner – a user – and a group.

When a file is created, its owner is the user who created it. The group to which the file belongs – the “owner” group – is the user’s current group. Users and groups have names, and they also have numeric identities, called user (or unique) identifier (UID) and group identifier (GID).

When you create a file, it belongs to you and belongs to your current group. Usually, this is the group you signed in to. By default, this is a group that shares the same name as your username and was created when you were created as a user on the system.

You can use the chown recursive command to can change property values ​​to something else. You can define a new owner, a new group, or a new owner and a new group at the same time. The owner of a file can change the ownership of the group, but only the root can change the ownership of the user as it involves another user. Without root privileges, you cannot force another user on the system to unintentionally “adopt” a file.

 

chown recursive

Why would you want to change owners?

Here are some examples of situations where you might want to do this:

Display of your groups, UID and GID

To list the groups you are in, you can use the groups chown recursive command.

For a list of groups, their numeric IDs, and your UID and GID, use the idcommand:

You can use some options with ID to refine the output.

  • -u: List your UID.
  • -g: List your effective (current) GID.
  • -nu: Enter your username.
  • -ng: List the name of your current group.

Viewing User and Group Ownership of a File

To see the owners of a file or directory, use the -l(long list) option with ls.

We can see that the name appears twice in the list. The leftmost appearance tells us that the owner of the file is a called user. The rightmost tells us that the file belongs to a group.

By default, when a Linux user is created, they are added to a private group named after their user name. They are the only member of this group.

This executable file is owned by the user and the group to which the file belongs is a private group.

This file is owned by the user, but the group to which the file belongs is called the research lab. This means that other members of the research lab group can access this file, depending on the file permissions that have been set for the members of that group.

Changing User Ownership

Let’s see some examples. This command will change the user’s ownership of the while.c file to the user.

One can use lsto see changes made to the properties of the file.

You can use chown recursive to change ownership of multiple files at once.

This changes user ownership over all three files.

You can use wildcards to select groups of files. This command will change user ownership of all files starting with the letter “c”.

All files will now have an owner. Note that no group property has been changed.

Let’s change the ownership of a directory. We’re just passing the directory name chownto instead of a file name.

To check the property properties of the directory we are using ls, but also use the -d(directory) option. This lists the properties of the directory, not the files it contains.

To change ownership of all files in a directory, you can use the -R(recursive) option. This option will change the user’s ownership of all files in the archive folder.

Now let’s look at the files in the archive directory.

Change group ownership

There are different ways to change group ownership.

To change the ownership of the group at the same time as you change the ownership of the user, pass the new owner’s name and the new group name with a colon “:” separating them. The group must already exist.

Both the owner of the user and the group to which the file belongs have been changed.

An abbreviated way to change the group ownership to the current group from the new owner, just to provide the colon and omit the group name.

User ownership and group ownership changed.

To change the group’s ownership only, precede it with a colon and omit the username. The owner of the user will not be changed.

The ownership of the group has been changed, but the ownership of the user remains the same.

Using Chown recursive with UID and GID Values

You can use UID and GID numeric values ​​with the chown recursive commander. This command will set the user and group ownership.

Possession is nine-tenths of the law

Or that’s what they say. But in Linux, ownership is an important part of file security, with file permissions providing the rest. Use the chownand chmodcommands to secure access to files on your system.

How we can use the chown recursive command on a Linux server or PC

When you are on a Linux server all files and directories are always owned by someone. You can therefore with the chown recursive command change the owner of any officer directory, here’s how to get there.

How does the chown recursive command work on Linux it’s mower how it works how I get on line PNG

On Linux, all directory files belong to a group or a user

You should know that Linux Server is a multi-user multitasking operating system. Linux Server allows multiple users to log on at the same time on a server or even a PC. In addition, several users can simultaneously connect to the same PC to work there.

To save a file or directory on a Linux server or PC you need to know who owns it, this makes it more secure, the Linux operating system will use a concept of file or directory owner. Each officer directory is owned by an owner such as a user or even a group.

When a file or directory has been created on a computer the owner of the child and the user who created it. The group this file belongs to and the current group of the user who created it. Each user group has a different name and also a digital identity called user id or unique identifier (UID) it also has a group id under the name of (GID)

When you create a new file or a directory it belongs to the one who created it it belongs to the group of this same user. And normally this is the group you logged in to. And by default, this is the group that shares the same username and which was created when the file was created as a system user.

You can use the chown recursive command to can change the property values ​​to something else. You can define a new owner, a new group, or a new owner and a new group at the same time. The owner of a file can change the ownership of the group, but only the root can change the ownership of the user, as this involves another user. Without root privileges, you cannot necessarily another user on the system “adopt” a file.

To change the owner you must use the chown recursive command with another owner name. So you can change the name of the owner, and also the new group where the new owner and new group are at the same time. The owner of a directory or file can change the owner of the group at any time, but only the administrator of the server or pc call root to change the owner of the user, as this involves another user of the server or from the PC. Without root administrator rights you cannot change the rights of another user, the system will prevent you from doing so. You have understood it, you need the root right of the PC or the server to be able to change the owner with the chown recursive command

Read more: CODEIGNITER TUTORIAL: HOW TO BUILD AND HOW TO USE

Why do you need to change owners on the chown recursive command?

I’ll give you some examples of situations where you need to change owners on a Linux server:

Chown recursive command: How to display your UID and GID groups?

To find out which group you belong to, just type the groups chown recursive command on Linux

chown recursive command groups

To find out the list of groups, their numerical identifier, and your UID AND GID identifier, use the chown recursive command

Here are the options you can use with the id chown recursive command.

id -u

id -g

id -nu

id -ng

Chown recursive command How do I view who owns a file?

To see the owners of a file or directory, use the -I option (long list) chown recursive command with ls.
To display who is the owner of a file or a directory you must use the command ls -l
What here is below
ls -l

You can see that the name root appears twice on this list. The leftmost rights display indicates that the owner and user are calling root. And the user furthest to the right is called root and therefore he tells us that he belongs to the group which is called root.

By default when creating a user under the chown recursive command he was added to the private group named by his username and they are the only members of this same group.

As you can see the root user and the group to which the root file belongs for this script.sh file

ls -l

This file is owned by the root user, and the group to which it belongs is also called root. This means that other members of the root group can access files from those permissions set by the group member.

 

For website maintenance service contact us.

Posted by Rebecca
Follow:
Rebecca is an Independent content writer for breldigital, She writes content on any given topic. She loves to write a case study article or reviews on a brand, Be it any topic, she nails it