I am not a Linux expert and mostly a developer but something that should work is not.
I have created a script that after a general install of Ubuntu 20.04 Linux configures my .NET Core website using NGINX as a proxy.
I download my setup script to the Ubuntu Server into a directory called /setup.
When I run this script it all works except for one small issue.
I have created a new nginx.conf file that I just want to copy over the original /etc/nginx/nginx.conf file. When I do this, I want the copied over file to keep the same rights and permissions as the original.
In my script I am using (I Googled):
sudo rsync -HDgop /setup/nginx/nginx.conf /etc/nginx/nginx.conf
When I do this (the script I run) I am logged in as a 'sudo' user let's say is called 'scarlett'.
If I change directory to /etc/nginx/nginx.conf and do a 'ls -la' the nginx.conf is now owned by scarlett:scarlett rather than the original root:root.
What am I doing wrong here?
Note: the script is written in PowerShell not Bash for reasons out of my control. Though it does work well bar this.
I have now tried this only at the command line and no matter what I do it simply doesn't work.
/etc/nginx/nginx.conf Initially has root:root ownership.
After:
sudo rsync -HDgop /setup/nginx/nginx.conf /etc/nginx/nginx.conf
sudo rsync -avz /setup/nginx/nginx.conf /etc/nginx/nginx.conf
sudo cp -p /setup/nginx/nginx.conf /etc/nginx/nginx.conf
/etc/nginx/nginx.conf always ends up with MySudoGroupUser:MySudoGroupUser ownership instead of root:root.
This is also same file system same machine.
I could manually re-own this file but doesn't that sort of defeat the point of the switches.
It seems that most blog / 'Google answers' and even some on here etc. are wrong.
Mostly folk seem to be getting very confused as to which ownership is moved or kept.
The following should work:
sudo rsync -ltD /setup/nginx/nginx.conf /etc/nginx/nginx.conf
I'm sure there is maybe an extra switch I have missed here (and feel free to add comment) noting I've missed compression as I don't think it's needed here nor any recursion (that folk doing directory stuff may want).
I did work this out from the man page but being honest I had to read it a couple of times myself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.