Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Created July 5, 2016 14:02
Show Gist options
  • Save bmatthewshea/53ed5148f09dfed50cebd10650ca551b to your computer and use it in GitHub Desktop.
Save bmatthewshea/53ed5148f09dfed50cebd10650ca551b to your computer and use it in GitHub Desktop.
#!/bin/bash
#Update file location to your needs/setup - assumes root access needed:
FILE=/etc/vsftpd/vsftpd-virt-htpasswds
#some checks
if [ "$EUID" -ne 0 ]
then echo "Please run this script as root or use sudo. Exiting."
exit
fi
if [ -z "$1" ] || [ -z "$2" ]; then
echo
echo "You have not entered a needed option."
echo "Usage:"
echo
echo "vsftp-passwd {ftp username} {ftp password}"
echo
echo "Exiting."
echo
exit
fi
if [ ! -e "$FILE" ] ; then
touch "$FILE"
fi
#command line tokens passed
USER=$1
PASS=$2
#exec it
htpasswd -p -b $FILE $USER $(openssl passwd -1 -noverify $PASS) &>/dev/null
if [ $? -eq 0 ]; then
echo "Command Succeeded."
else
echo "Command Failed!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment