I use CloudFormation to spin up a stack with one EC2 instance. Once the instance is running, I want to be able to use "Run command" feature to execute some scripts, but not as root user. That's why, in the init script (UserData
section of the YAML template), I create a new user by following the docs:
sudo adduser sometestuser
sudo su - sometestuser
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
I'm assuming that after the instance is initialized completely, I can use this user to execute some scripts. I then log in to the instance or use "Run command" and execute such command to verify that the user exists:
id -u sometestuser
Problem
After some time after the instance is created (up to 10 minutes, as I noticed so far), it looks like the user gets removed. For example, after SSHing to the host:
[...@ip-10-0-44-213]/% date && id -u sometestuser
Tue Sep 11 10:25:41 UTC 2018
59844
[...@ip-10-0-44-213]/% date && id -u sometestuser
Tue Sep 11 10:28:03 UTC 2018
59844
[...@ip-10-0-44-213]/% date && id -u sometestuser
Tue Sep 11 10:31:42 UTC 2018
id: sometestuser: no such user
[...@ip-10-0-44-213]/% date && id -u sometestuser
Tue Sep 11 10:32:28 UTC 2018
id: sometestuser: no such user
You can see that the user existed for several minutes, and then it disappeared. I managed to reproduce it every time I spin up the instance.
Question
Why does it work like this? Is there some background job that removes custom users that possibly don't comply with some rules?