I was performing some experiments in Docker and found a strange behaviour.
I was able to override the ownership of a file created with the root user inside the Docker with another user without root permissions.
Below are the steps to reproduce it:
$> docker run -dit ubuntu:16.04 bash $> docker exec -it cont_id bash $> apt update && apt install -y vim $> useradd cp -m $> vim /home/cp/hello.txt # Write some text and save it $> su cp $> cd ~/ && ls -latr; # Will list hello.txt with user and group as root $> vim hello.txt # Write some text and try saving it normally which will fail. # Try saving it with `:wq!` Voila, it is saved and the user and group to which the file belongs also change to the new user.
I have done a terminal recording for this and the same is posted here.
echo "sometext " >> /filePath, doesn't change the inode value. Vim does change the inode value every time. Thanks.