software: backfire 10.03+ Xwrt
Right now,when the firstboot after flash the firmware, i have to first open a web UI to set a password for the user "root", after that,i could use SSH to login the system with the user name "root" and the password i set before, it is kind of complex.
so i want to set a default password for the user "root" into the firmware, so that i dont need to open web UI to set the password after the firstboot.
What i did is, first i read the script source code of Xwrt about how to set the "root" password, it use the command "passwd" in the following way:
(
echo "12345678"
sleep 1
echo "12345678"
)|passwd root
this will set the root's password to "12345678".
and also, i see the default file /etc/passwd said that, before setting a password to root , the password section of root will be a '!' like:
root:!:0:0:root:/root:/bin/ash (in the default /etc/passwd)
so i create a script named "setpass.sh", and execute it in /etc/rc.local , what i want is if there is no password set to root, create a password "12345678" to it , but if there is a password of root, do not do anything.
#!/bin/sh
var=`grep '^root:' /etc/passwd | cut -d: -f2 `
if [ $var='!']
then
(
echo "12345678"
sleep 1
echo "12345678"
)|passwd root
fi
it works, but only achiver half of my purpose. when there is no root password , it will set it to "12345678" (for example,the firstboot after flash firmware). but if i change the root password to other string through ssh, after reboot, it will set root password to "12345678" again!!! which means the if[ $var='!' ] does not work!
right now,what i want to know is is there anyother way to set a default root password rather than what i did???
why if [ $var='!' ] does not work??? is there some mistake in my script or at the boot time, the /etc/passwd always display "root:!:0:0:root:/root:/bin/ash" ???