Skip to content

Instantly share code, notes, and snippets.

@manuel-rabade
Created December 29, 2014 04:57
Show Gist options
  • Save manuel-rabade/f34a406c259e79b448d7 to your computer and use it in GitHub Desktop.
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
#!/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