Created
December 29, 2014 04:57
-
-
Save manuel-rabade/f34a406c259e79b448d7 to your computer and use it in GitHub Desktop.
Genera un password para un usuario y se lo guarda en ~/.passwd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER=$1 | |
CHARS=12 | |
HOME=$(awk -F: -v v="$USER" '{if ($1==v) print $6}' /etc/passwd) | |
PASSWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c $CHARS) | |
if [ -z "$HOME" ]; then | |
echo "$USER is a user?" | |
exit | |
fi | |
touch $HOME/.passwd | |
chown $USER $HOME/.passwd | |
chmod 600 $HOME/.passwd | |
echo $PASSWD > $HOME/.passwd | |
echo $PASSWD | passwd --stdin $USER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment