Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. username=$1
  4. password=$2
  5. usersGroup="sftpusers"
  6. usersSkelDir="/etc/skel-sftpusers"
  7.  
  8. usersJailDir="/home"
  9. usersRootDir=${usersJailDir}/${username}
  10. usersHomeDir=${usersRootDir}/home
  11. usersStartDir=${usersHomeDir}/${username}
  12.  
  13. # Get the ${usersGroup} GID
  14. usersGID=$(getent group | grep ${usersGroup} | tr ':' ' ' | awk '{print $3}')
  15.  
  16. # Make the users's home directory so useradd doesn't complain
  17. mkdir -p ${usersHomeDir}
  18.  
  19. # Add the user. Set their jail directory, their GID, their skel, their home, their shell, and their username
  20. useradd --skel ${usersSkelDir} --base-dir ${usersHomeDir} --gid ${usersGID} --create-home --shell /sbin/nologin ${username}
  21.  
  22. # Change the uers's home directory to work correctly after the jail
  23. usermod --home "/home/${username}" ${username}
  24.  
  25. # Set permission for the user's root directory
  26. chown root:root ${usersRootDir}
  27. chmod 751 ${usersRootDir}
  28. # Set permission for the user's home directory
  29. chown root:root ${usersHomeDir}
  30. chmod 751 ${usersHomeDir}
  31. # Set permission for their starting directory (still not allowed to write...)
  32. chown root:${usersGroup} ${usersStartDir}
  33. chmod 750 ${usersStartDir}
  34. # And then set permissions for the users's starting directory (and all other files inside it recursively)
  35. chown -R ${username}:${usersGroup} ${usersStartDir}/*
  36. chmod -R 770 ${usersStartDir}/*
  37.  
  38. # Change their password to the one provided
  39. echo ${username}:${password} | chpasswd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement