Advertisement
SoulofSorrow

vsFtp User Script

Mar 7th, 2021
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #!/bin/bash
  2. # Purpose - Script to add a user to Linux system including passsword
  3. # Author - Vivek Gite <www.cyberciti.biz> under GPL v2.0+
  4. # ------------------------------------------------------------------
  5. # Am i Root user?
  6. if [ $(id -u) -eq 0 ]; then
  7.         read -p "Enter username: " username
  8.         read -p "Enter Directory: " dir
  9.         read -s -p "Enter password: " password
  10.         egrep "^$username" /etc/passwd >/dev/null
  11.         if [ $? -eq 0 ]; then
  12.                 echo "$username exists!"
  13.                 exit 1
  14.         else
  15.                 pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  16.                 echo $username >> /etc/vsftpd.userlist
  17.                 useradd -m -p "$pass" -d "$dir" -g www-data -s /bin/ftponly "$username"
  18.                 chmod -R 777 "$dir"
  19.                 [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
  20.         fi
  21. else
  22.         echo "Only root may add a user to the system."
  23.         exit 2
  24. fi
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement