Changing ROOT Password with Bash Scripting

So you know when you spin up a new droplet and you first SSH into it and it asks you for the current password, then to change the password [twice]? Could this be done automatically say via a Bash/Shell script?

I’m looking to automate the process to where nobody has to SSH into a droplet and change it manually.

Surely possible, I just don’t know much about bash/shell scripting.



Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I’m still confused here. How can I change the root pw via Bash so i don’t need to SSH in and do it manually or use SSH keys

The quickest solution would be to set up SSH keys on your account.

With this in place any client with the ssh private key will be able to make an ssh connection to your droplet without the need for a password and this password change prompt is never shown.

Alternately you could use the user-data section on the create screen to pass bash commands to your droplet on creation to set the root password. A few methods to accomplish this can be found here.

Thank you, I appreciate the write up!