If you have not lost the admin password then it is better to set in the Grafana UI. If you need to set the password in a script then the Grafana API can be used. Here is an example using curl with basic auth: