By default, the owner cannot use the chown command to change the owner of a file or directory. In addition, the owner can only use the chgrp command to change the group of a file to a group in which the owner belongs by default. For example, if the owner of a file only belongs to the staff and sysadm groups, the owner can only change the group of a file to staff or sysadm group. Also, be aware that there can be other restrictions on changing ownership and groups on NFS-mounted file systems.
How to Change Permissions and Owners via Command Line
groupmod command in Linux with examples - GeeksforGeeks
Every file is associated with an owner and a group. You can use chown and chgrp commands to change the owner or the group of a particular file or directory. Even if you already know this command, probably one of the examples mentioned below might be new to you. This is the default behavior of the chown command. On a related note, if you want to change the permission of a file, you should use chmod command. If you are a beginner, you should start by reading the basics of file permissions.
The chgrp from ch ange gr ou p command may be used by unprivileged users on Unix-like systems to change the group associated with a file system object such as a file, directory, or link to one of which they are a member. A file system object has 3 sets of access permissions, one set for the owner, one set for the group and one set for others. Changing the group of an object could be used to change which users can write to a file. It is also available in the Plan 9 and Inferno operating systems and in most Unix-like systems.
I'm using Puppet to manage server configurations and it's got some nice features for automating the set-up of users. Unfortunately when I initially set-up the puppet directives, I overlooked setting the UID for each user which means that the UIDs assigned have been randomly created. As I want to maintain UIDs across all the boxes I'm using, it means there's a need to migrate users's uid's and gids that are different. Using any of the scripts that follow is done entirely at your own risk. As Jared pointed out in the comments it's a good idea to specify -h for the chgrp and chown commands so that symlinks aren't followed.