How to change the file permission of the file created by the lxc container script
Welcome!
If there is a file /home/ubuntu/myfile.txt
in the container mycontainer
and you want to change the permissions from the host, you would run from the host:
incus exec mycontainer -- chmod 644 /home/ubuntu/myfile.txt
Thanks for your replay simos
the file is created by the script run by the container with the permission only -rw------ i need to change it to -rw-r----- is it possible use
incus exec mycontainer – chmod 644 /home/ubuntu/myfile.txt
in script to change the permission?
If the permissions were rw- --- ---
and you want to make them rw- r-- ---
, then you can either run the following to add read access for the group (second triplet).
incus exec mycontainer -- chmod g+r /home/ubuntu/myfile.txt
or set directly to rw- r-- ---
,
incus exec mycontainer -- chmod 640 /home/ubuntu/myfile.txt
Alternatively, you can modify your script and set the umask according to the instructions. By setting a value to umask
, you can control the default permissions when a new file is created.
$ umask
0002
$ touch myfile.txt
$ ls -l myfile.txt
-rw-rw-r-- 1 user user 0 Μαρ 30 21:39 myfile.txt
$ rm myfile.txt
$ umask 0026
$ touch myfile.txt
$ ls -l myfile.txt
-rw-r----- 1 user user 0 Μαρ 30 21:39 myfile.txt
$