Almost certainly, & there is probably more than one approach.
Before I outline one idea, let me say that I think it would be easier to do this manually if there are only "5 or 6 virtual servers"; unless the task will need to be performed on a fairly regular basis.
I would give my script a list of the VM's & their root passwords by name or IP address. This could be in a file or embedded in the script. Then for each VM, I would
ssh in as root, run an appropriate
sed -i command, & log out.
This assumes several things:
- You're making the same change to all the /etc/passwd files.
- The box that runs the script has network access to the VM's.
- sshd is running on all the VM's.
- You have the necessary root passwords.
- You can keep them secure in the script or the VM/password list file.
- You have sed on the VM's & it's the same sed, or at least they all work the same.
- etc., etc., etc. . . . (homage to Yul Brynner)