To add onto this, here is an example of the bash script we use to install universal forwarders to all have a random password. We don't save the password as it is easy to reset with access to the filesystem and access is rarely a need to directly connect to a universal forwarder in our instance. If the password needs to be saved you could probably add in there to have it write password and hostname to a file somewhere to retrieve later. We have a similar script for Windows forwarders as well.
#!/bin/bash
groupadd -g 777 splunk
useradd -m -u 777 -g splunk splunk
tar -xzvf <forwarder-version>.tgz -C /opt/
chown -R splunk:splunk /opt/splunkforwarder/
su - splunk -c "/opt/splunkforwarder/bin/splunk start --accept-license"
su - splunk -c "/opt/splunkforwarder/bin/splunk set deploy-poll <deployment-server>:8089 -auth admin:changeme"
splpassword=$(head -c 500 /dev/urandom | sha256sum | base64 | head -c 32)
su - splunk -c "/opt/splunkforwarder/bin/splunk edit user admin -password $splpassword -auth admin:changeme"
su - splunk -c "/opt/splunkforwarder/bin/splunk restart"
/opt/splunkforwarder/bin/splunk enable boot-start -user splunk
... View more