Ever need to change (or set) passwords for a large number of users? Something like this code snippet may help.
# find all the usernames with bash logins
usernames=$(cat /etc/passwd | grep bash | sed 's/:.*//g)
for user in $usernames; do
echo "somepassword" | passwd --stdin $user
done
The --stdin option does not work in all version of passwd (e.g. it does not work on the Debian/Ubuntu-based versions). Instead, the chpasswd command works everywhere (so is probably the better option):
# find all the usernames with bash logins
usernames=$(cat /etc/passwd | grep bash | sed 's/:.*//g)
for user in $usernames; do
echo "$user:somepassword" | chpasswd
done