change root password using bash script

Viewed 12622

SO, when I order a VPS, I get a random password from them which I need to change,

I basically use centos 6 x64

I was thinking to make a bash script which when I run will change the password of the VPS to a default common password which I would like to use with all my VPS.

So, my question - Is it possible?

I am thinking to use this inside the bash .sh script, is my code correct,

#!/bin/bash
passwd
echo jadaruine

If not what should be the code?

2 Answers

You want the chpasswd command:

sudo sh -c 'echo username:password | chpasswd'

You might also want to look at chage for password expiry settings.

You can do the following to change the password on centos

#!/bin/bash
echo "jadaruine" | passwd --stdin user
Related