You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
998 B
52 lines
998 B
#!/bin/bash
|
|
|
|
getRandomPasswd() {
|
|
local k
|
|
|
|
while :; do
|
|
k=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom 2> /dev/null | head -c${1:-32} )
|
|
if [ $(echo -n $k | wc -c) = 32 ]; then
|
|
break
|
|
fi
|
|
echo "Wait for entropy avail : $(cat /proc/sys/kernel/random/entropy_avail)" >&2
|
|
sleep 1
|
|
done
|
|
echo -n $k
|
|
}
|
|
|
|
# main
|
|
|
|
echo "=== $0"
|
|
|
|
|
|
if [ ! -e /etc/vdn-$MODE-initialized ]; then
|
|
|
|
# regenerate ssh_host_keys
|
|
|
|
rm -f /etc/ssh/ssh_host_*
|
|
|
|
dpkg-reconfigure openssh-server
|
|
|
|
#systemctl restart ssh
|
|
|
|
# Random root and test password
|
|
|
|
echo "Random passwords."
|
|
|
|
k=$(getRandomPasswd)
|
|
#echo "root passwd : $k"
|
|
passwdRoot=$k #$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32};)
|
|
k=$(getRandomPasswd)
|
|
#echo "test passwd : $k"
|
|
passwdTest=$k #$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32};)
|
|
|
|
cat <<- EOF | chpasswd
|
|
root:$passwdRoot
|
|
test:$passwdTest
|
|
EOF
|
|
|
|
touch /etc/vdn-$MODE-initialized
|
|
|
|
fi
|
|
|