Sometimes I need to compress and make backups of files and directories. but when I uncompress the tar.gz file, the owner and group permissions change to root.

I found a way to keep (retain) the group and user permssions with this command:

example: suppose i want to make a backup copy of my public_html directory which is located at /var/www/html/ and want to compress it retaining the files group and user owership permissions. so to backup my public_html (/var/www/html/public_html) i would move to the html directory:

change directory to where the to be tar file is located:
CODE:
cd var/www/html


now execute this command to do the compressing of public_html
CODE:
tar -pczf public_html.tar.gz public_html/