By Kashif Asif
can anyone help me how to create a shell or python script by which i can change root password when i create a new droplet. actually problem is that when i create a new droplet it email me ip, username and password to my email. its good. but i want to create a script by which i can change the password of root without any prompt from a php website. ( i am using ssh script to execute a command from a php and i will run this bash script from this php website). Script should be for Ubuntu. Example: when we when we want to connect our new droplet with serverpiolat.io using our ip and ssh password then it install all the packages. as it is required for new created droplet to change password first time.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This can be done by using expect. First install expect on your server.
apt-get install expect
#!/usr/bin/expect -f
spawn ssh root@ip
# Remove this section if you are not expecting this message.
expect "Are you sure you want to continue connecting (yes/no)?"
sleep 1
send "yes\r"
expect "password:"
sleep 1
send "<current_password>\r"
expect "(current) UNIX password:"
sleep 1
send "<current_password>\r"
expect "Enter new UNIX password:"
sleep 1
send "<new_password>\r"
expect "Retype new UNIX password:"
sleep 1
send "<new_password>\r"
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.