Score:0

tar change permission of parent directory to 775

cn flag

I tried to untar file with below command

sudo -u ubuntu tar -xzf tar.tgz -C "$(dirname "/home/ubuntu/deploy/")"

The tar log looks like

./
./deploy/deploy_scy.yml
./deploy/rollback_app.yml
./deploy/deploy_haproxy_single.yml

But the problem is that tar changed permission of /home/ubuntu from 750 to 775

root@ip-10-10-78-205:/home/ubuntu# ll
total 7016
drwxrwxr-x  7 ubuntu ubuntu    4096 Mar 21 07:41 ./
drwxrwxr-x 25 ubuntu ubuntu   12288 Mar 22 05:18 deploy/

How can I preserve the permission(750) of /home/ubuntu directory? This issue only happens in Ubuntu 22.04, I also don't understand why.

In Ubuntu 18.04, I use the same command, the permission /home/ubuntu still keeps as 750 as expected

muru avatar
us flag
It didn't change the parent directory. You can clearly see `./` in the output, which is `/home/ubuntu` in the command you ran. If you don't want the current working directory to be modified, you shouldn't be extracting it.
Score:0
us flag

It didn't change the parent directory. It change the current directory. You can clearly see ./ in the output, which is /home/ubuntu from the command you ran, and that directory got modified.

If you don't want the current working directory to be modified, you shouldn't be extracting .. Maybe instead extract just the deploy directory:

sudo -u ubuntu tar -xzf tar.tgz -C "$(dirname "/home/ubuntu/deploy/")" ./deploy

I can't reproduce this in an 18.04 Docker container (it behaved like you say 22.04 does), so I think your tar file was simply different in your 18.04 deployment.


There is a difference between these two ways of creating tar files in a directory containing a deploy directory:

tar cvf foo.tar ./deploy
tar cvf foo.tar .

The latter will contain an entry for ./ with the permissions of the current working directory in which it was ran. For example, the first command will result in:

% tar tvf foo.tar
drwxr-xr-x muru/muru 0 2023-03-22 14:46 ./deploy/
-rw-r--r-- muru/muru 0 2023-03-22 14:46 ./deploy/foo

vs. the following for the second command:

# tar tvf foo.tar
drwxr-xr-x muru/muru 0 2023-03-22 05:57 ./
drwxr-xr-x muru/muru 0 2023-03-22 05:46 ./deploy/
-rw-r--r-- muru/muru 0 2023-03-22 05:46 ./deploy/foo

When extracting, the latter will update the permissions of whichever directory it was in to the stored permissions. It's likely your tar file was created like the first one in 18.04 and like the second one in 22.04.

Tien Dung Tran avatar
cn flag
Actually, the tar file is the same.
muru avatar
us flag
Then either (a) something else prevented it from changing the permissions, or (b) it was a bug that was fixed but you don't have the latest updates in 18.04 yet. Either way, I'd consider the behaviour you say you see in 18.04 to be a bug and the one in 22.04 to be correct.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.