Adding users to VM instatiated from linux template


What is the correct way to add users to linux VM instantiated from template?

The quickest way is to add a START_SCRIPT in context. Didn’t try but it
should be something like

  START_SCRIPT="useradd -m -s /bin/bash test_user ; echo -e \"pass\npass\"
| passwd test_user"

You could even combine it with user inputs to ask the user for the passwd
(just add another var in CONTEXT with the user input value and source the script to get it)

It seems that START_SCRIPT is run every time VM reboots.

Is there a way to run certain scripts just once when VM is started for the first time after instatiating from template?

You can easily add a “state file” for example create a file /.configured
and make your script check for it, or maybe just check if any of the
configurations was already performed.

I have also added start_script in VM template and instantiated a VM like below:

When i opened the VNC server of that VM. It is not login using the username and password given in the context.
Login: test_user
Password: test_user
It is not working…

What is the right way to add a commands in start script to execute after VM is instantiated?