Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- genpasswd() {
- local l=$1
- [ "$l" == "" ] && l=5
- tr -dc a-z < /dev/urandom | head -c ${l} | xargs
- }
- checkuser() {
- getent passwd $USERNAME > /dev/null 2&>1
- if [ $? -eq 0 ]; then
- return 1
- else
- return 0
- fi
- }
- createuser() {
- useradd $USERNAME -d /home/$GROUP/$USERNAME/ -s /bin/false -G $GROUP
- cd /home/$GROUP
- chown root:root $USERNAME
- chmod 755 $USERNAME
- cd /home/$GROUP/$USERNAME/
- mkdir public_html
- cd $HTDOC
- mkdir $FOLDER
- echo "mount --bind $HTDOC/$FOLDER /home/$GROUP/$USERNAME/public_html" | sudo tee -a $RUNBIND
- echo $GENPASS | sudo passwd --stdin $USERNAME
- mount --bind $HTDOC/$FOLDER /home/$GROUP/$USERNAME/public_html
- cd /home/$GROUP/$USERNAME/
- chown $USERNAME:apache public_html
- chmod 775 -R public_html
- chmod g+s -R public_html
- chmod u+s -R public_html
- }
- cetak(){
- echo "+----------------------------------+"
- echo "| User Account Information |"
- echo "+----------------------------------+"
- echo " SFTP :- "
- echo " Username : $USERNAME "
- echo " Password : $GENPASS "
- echo " "
- echo " *** Done $(date) *** "
- echo " "
- echo "+----------------------------------+"
- }
- clear
- echo "***********************************************************************"
- echo "* Welcome to SFTP Only Shell Account Creator *"
- echo "***********************************************************************"
- echo ""
- ROOTUSER=""
- ROOTPASS=""
- HTDOC="/var/www/html"
- RUNBIND="/opt/runbind.sh"
- GROUP="sftponly"
- GENPASS=$(genpasswd)
- echo "---> SFTP INFO <---"
- read -p "Enter Username for SFTP : " USERNAME
- read -p "Enter Folder in WWW: " FOLDER
- ROOTUSER="root"
- echo "Folder in www: $FOLDER"
- echo "---> MySQL INFO <---"
- echo "Root user :->root"
- echo ""
- NEWUSER=$USERNAME
- if checkuser -eq 0; then
- createuser
- cetak
- exit
- else
- echo "error"
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement