Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #!/bin/bash
  2. # add following to bottom of /etc/ssh/sshd_config and TEST FIRST using sshd -t or something
  3. # and make sure if sftp is already defined, to comment out that subsystem definition
  4.  
  5. # Subsystem sftp internal-sftp
  6. # Match Group sftponly
  7. # PasswordAuthentication yes
  8. # ChrootDirectory /sftp/%u
  9. # ForceCommand internal-sftp -u 0000
  10. # AllowTcpForwarding no
  11. # PermitTunnel no
  12. # X11Forwarding no
  13.  
  14.  
  15. # create these groups first
  16. FTPGROUP="sftponly"
  17. grep -qE "^$FTPGROUP" /etc/group || addgroup "$FTPGROUP"
  18.  
  19.  
  20. # make the group listed below
  21. SUPP_GROUPS="extusers"
  22. grep -qE "^$SUPP_GROUPS" /etc/group || addgroup "$SUPP_GROUPS"
  23.  
  24. HOMEROOT="/sftp"
  25. [ -d "$HOMEROOT" ] || {
  26. mkdir -m 0754 -p "$HOMEROOT"
  27. chown "root:$SUPP_GROUPS" "$HOMEROOT"
  28. }
  29.  
  30.  
  31. FTPUSER="$1"
  32. FTPPASS="$2"
  33.  
  34. [ "$FTPUSER" ] || {
  35. echo "Needs a username!" >&2
  36. exit 3
  37. }
  38.  
  39. id -u "$FTPUSER" &>/dev/null && {
  40. echo "User $FTPUSER already exists!" >&2
  41. exit 3
  42. }
  43.  
  44. [ "$FTPPASS}" ] || {
  45. echo "Needs a password!" >&2
  46. exit 3
  47. }
  48.  
  49. useradd \
  50. --home "/" \
  51. --shell /bin/false \
  52. --gid "$FTPGROUP" \
  53. --groups "$SUPP_GROUPS" \
  54. "$FTPUSER"
  55.  
  56. chpasswd --crypt-method=SHA512 <<<"$FTPUSER:$FTPPASS"
  57.  
  58. # The goal here is to make all files in user subdirs be read-write
  59. # for supp group so any sync process can be done without root perms.
  60. mkdir -p "$HOMEROOT/$FTPUSER"/{incoming,outgoing}
  61. chown -R "$FTPUSER:$SUPP_GROUPS" "$HOMEROOT/$FTPUSER"/*
  62. chmod -R ug+rwx "$HOMEROOT/$FTPUSER"/*
  63. chmod g+s $HOMEROOT/$FTPUSER/*
  64. setfacl -m "default:group::rwx" "$HOMEROOT/$FTPUSER"/*
  65. chown "root:$SUPP_GROUPS" "$HOMEROOT/$FTPUSER"
  66.  
  67. chmod 0750 "$HOMEROOT/$FTPUSER"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement