README.Virtual-Users 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. ------------------------ VIRTUAL USERS ------------------------
  2. Virtual users is a simple mechanism to store a list of users, with their
  3. password, name, uid, directory, etc. It's just like /etc/passwd. But it's
  4. not /etc/passwd. It's a different file, only for FTP.
  5. It means that you can easily create FTP-only accounts without messing up
  6. your system accounts.
  7. In addition, virtual users files can store individual quotas, ratios,
  8. bandwidth, etc. System accounts can't do this.
  9. Thousands of virtual users can share the same system user, as long as they
  10. all are chrooted and they have their own home directory.
  11. *IMPORTANT* If you are planning to use the virtual users feature, and
  12. unless your operating system already provides a secure password
  13. hashing function, please install libsodium (http://doc.libsodium.org)
  14. before compiling Pure-FTPd.
  15. A good thing to do before using virtual users is to create a system user
  16. for this. Of course, you can use any existing account like "nobody" (but not
  17. root), but it's better to have a dedicated account.
  18. Let's create an "ftpgroup" group and an "ftpuser" user.
  19. Linux/OpenBSD/NetBSD/Solaris/HPUX/OSX/a lot of other Unix-like systems:
  20. groupadd ftpgroup
  21. useradd -g ftpgroup -d /dev/null -s /etc ftpuser
  22. FreeBSD/DragonflyBSD:
  23. pw groupadd ftpgroup
  24. pw useradd ftpuser -g ftpgroup -d /dev/null -s /etc
  25. Then, all maintenance of virtual users can be made with the "pure-pw"
  26. command. You can also edit the files by hand if you want.
  27. Files storing virtual users have one line per user. These lines have the
  28. following syntax:
  29. <account>:<password>:<uid>:<gid>:<gecos>:<home directory>:<upload
  30. bandwidth>:<download bandwidth>:<upload ratio>:<download ratio>:<max number
  31. of connections>:<files quota>:<size quota>:<authorized local IPs>:<refused
  32. local IPs>:<authorized client IPs>:<refused client IPs>:<time
  33. restrictions>
  34. Fields can be left empty (exceptions: account, password, uid, gid, home
  35. directory) .
  36. Passwords are compatible with the hashing function used in /etc/passwd or
  37. /etc/master.passwd . They are crypto hashed with blowfish, md5, multiple-des
  38. and simple des, in this order, according to what your system has support fort.
  39. ------------------------ CREATING A NEW USER ------------------------
  40. To add a new user, use the following syntax:
  41. pure-pw useradd <login> [-f <passwd file>] -u <uid> [-g <gid>]
  42. -D/-d <home directory> [-c <gecos>]
  43. [-t <download bandwidth>] [-T <upload bandwidth>]
  44. [-n <max number of files>] [-N <max Mbytes>]
  45. [-q <upload ratio>] [-Q <download ratio>]
  46. [-r <allow client ip>/<mask>] [-R <deny client ip>/<mask>]
  47. [-i <allow local ip>/<mask>] [-I <deny local ip>/<mask>]
  48. [-y <max number of concurrent sessions>]
  49. [-C <max number of concurrent login attempts>]
  50. [-M <total memory (in MB) to reserve for password hashing>]
  51. [-z <hhmm>-<hhmm>] [-m]
  52. Let's create "joe", whose home directory will be /home/ftpusers/joe . The
  53. system account associated with "joe" is "ftpusers".
  54. pure-pw useradd joe -u ftpuser -d /home/ftpusers/joe
  55. Joe's password is asked twice.
  56. With -d, joe will be chrooted. If you want to give joe access to the whole
  57. filesystem, use -D instead of -d.
  58. You don't need to create /home/ftpusers/joe if you run pure-ftpd with the
  59. -j (--createhome) switch. With that switch, home directories will
  60. automatically be created when users will log in for the first time.
  61. The "-z" option allow a user to connect only during a range of day time.
  62. For instance, with -z 0900-1800, joe will only be able to connect from 9 am
  63. to 18 pm. Warning: a user that connected during authorized hours can
  64. finish his session after these authorized hours.
  65. -r and -R are handy to restrict where the user can connect from. They can be
  66. followed by a simple IP/mask pair (-r 192.168.1.0/24), multiple pairs
  67. separated by a coma (-r 192.168.1.0/24,10.1.0.0/16,127.0.0.1/32), single IPs
  68. (-r 192.168.1.4,10.1.1.5), host names (-r bla.bla.net,yopcitron.com), or any
  69. combination of those.
  70. -y is to restrict the number of concurrent sessions a user can have
  71. at the same time. '' or 0 mean unlimited. Avoid this feature on very loaded
  72. servers. Use per-ip limits instead.
  73. Ok, "joe" has been created. By default, the list of virtual users is stored
  74. in the /etc/pureftpd.passwd file (you can of course change this with -f
  75. <file>) .
  76. Let's have a look at its content:
  77. joe:$7$C6..../....swVShTUX9kLJepm0vvj7dUXPqtULzQ9G3GT/GAO3bd3$GMHJRyUdSRwNROunwtRbEDHlx5t3eNQew7bb1dz29K2:500:101::/home/ftpusers/joe/./:::::::::::::
  78. Passwords are hashed with the most secure hash function your system supports.
  79. Hashes are tried in this order: argon2, scrypt, bcrypt, SHA-512, MD5.
  80. SHA-512 and MD5 should not be used any more. bcrypt requires crypt(3)
  81. from the C library to support it, which is commonly the case on BSD
  82. systems, but is only present on some Linux distributions.
  83. Argon2 and scrypt are the recommended functions, and require pure-ftpd to be
  84. compiled in presence of libsodium. Note that a login attempt will require up
  85. to 64 Mb memory, and 100% of a CPU core. The number of simultaneously allowed
  86. sessions should be tuned accordingly to avoid resources starvation.
  87. ------------------------ CHANGING INFO ------------------------
  88. Once virtual users have been created, you can edit their info. For instance
  89. you can add bandwidth throttling, change quotas, add their full name, update
  90. ratio, etc.
  91. The "pure-pw usermod" command works just like "pure-pw useradd" except that
  92. it modifies an existing account instead of creating a new one.
  93. For instance, we will add a quota to Joe. Joe should be limited to 1000
  94. files and 10 Megabytes.
  95. pure-pw usermod joe -n 1000 -N 10
  96. Let's have a look at /etc/pureftpd.passwd:
  97. joe:$7$C6..../....swVShTUX9kLJepm0vvj7dUXPqtULzQ9G3GT/GAO3bd3$GMHJRyUdSRwNROunwtRbEDHlx5t3eNQew7bb1dz29K2:500:101::/home/ftpusers/joe/./::::::1000:10485760::::::
  98. As you can see, the size quota is stored in bytes in the file.
  99. ------------------------ RESETTING ATTRIBUTES ------------------------
  100. To disable file quotas, use pure-pw usermod <user> -n ''
  101. To disable size quotas, use pure-pw usermod <user> -N ''
  102. To disable ratios, use pure-pw usermod <user> -q '' -Q ''
  103. To disable download bandwidth throttling, use pure-pw usermod <user> -t ''
  104. To disable upload bandwidth throttling, use pure-pw usermod <user> -T ''
  105. To disable IP filtering, use pure-pw usermod <user> <-i,-I,-r or -R> ''
  106. To disable time restrictions, use pure-pw usermod <user> -z ''
  107. To disable the number of concurrent sessions, use pure-pw usermod <user> -y ''
  108. ------------------------ DELETING USERS ------------------------
  109. We won't delete Joe at this time. Joe is a fine guy :) But FYI, deleting an
  110. user is as simple as running "pure-pw userdel", whose syntax is:
  111. pure-pw userdel <login> [-f <passwd file>] [-m]
  112. Deleting Joe would be:
  113. pure-pw userdel joe
  114. The content of his home directory is kept. Delete it by hand if you want.
  115. ------------------------ CHANGING PASSWORDS ------------------------
  116. To change the password of a user, use "pure-pw passwd":
  117. pure-pw passwd <login> [-f <passwd file>] [-m]
  118. ------------------------ DISPLAYING INFO ------------------------
  119. To review info about one user, reading the /etc/pureftpd.passwd file is ok,
  120. but it's not really human-friendly.
  121. It's why you can use "pure-pw show", whose syntax is:
  122. pure-pw show <login> [-f <passwd file>]
  123. Let's try with joe:
  124. pure-pw show joe
  125. Login : joe
  126. Password : $7$C6..../....swVShTUX9kLJepm0vvj7dUXPqtULzQ9G3GT/GAO3bd3$GMHJRyUdSRwNROunwtRbEDHlx5t3eNQew7bb1dz29K2
  127. UID : 500 (ftpuser)
  128. GID : 101 (ftpgroup)
  129. Directory : /home/ftpusers/joe/./
  130. Full name :
  131. Download bandwidth : 0 Kb (unlimited)
  132. Upload bandwidth : 0 Kb (unlimited)
  133. Max files : 1000 (enabled)
  134. Max size : 10 Mb (enabled)
  135. Ratio : 0:0 (unlimited:unlimited)
  136. Allowed local IPs :
  137. Denied local IPs :
  138. Allowed client IPs : 192.168.0.0/16
  139. Denied client IPs : 192.168.1.1,blah.verybadhost.com
  140. Time restrictions : 0900-1800 (enabled)
  141. Max sim sessions : 0 (unlimited)
  142. "/./" at the end of a home directory means that this user will be chrooted.
  143. ------------------------ COMMITTING CHANGES ------------------------
  144. IMPORTANT:
  145. You can add, modify and delete users with the previous commands, or by
  146. editing /etc/pureftpd.passwd by hand. But the FTP server won't consider the
  147. changes you make to that file, until you commit them.
  148. Committing changes really means that a new file is created from
  149. /etc/pureftpd.passwd (or whatever file name you choose) . That new file is a
  150. PureDB file. It contains exactly the same info than the other file. But in
  151. that file, accounts are sorted and indexed for faster access, even with
  152. thousands of accounts. PureDB files are binary files, don't try to view them
  153. or your terminal will beep like hell.
  154. Let's create a PureDB file from /etc/pureftpd.passwd. The indexed file will
  155. be called /etc/pureftpd.pdb (as always, choose whatever name you like):
  156. pure-pw mkdb
  157. this reads /etc/pureftpd.passwd and creates /etc/pureftpd.pdb by default, but
  158. to read another file, add the pdb file, optionnaly followed by -f <passwd file>
  159. For instance:
  160. pure-pw mkdb /etc/accounts/myaccounts.pdb -f /etc/accounts/myaccounts.txt
  161. All modifications you made to the virtual users database will be committed
  162. automatically: all new accounts will be activated at the same time and all
  163. deleted users won't be able to log in as soon as you'll have hit the Return
  164. key.
  165. There's no need to restart the pure-ftpd server to commit changes.
  166. You can also change something to the text passwords file (add users, change
  167. password, delete users, etc) and automatically run
  168. "pure-pw mkdb /etc/pureftpd.pdb" afterwards. To do so, just use the -m
  169. switch:
  170. pure-pw passwd joe -m
  171. This command will change Joe's password in pureftpd.passwd *and* commit the
  172. change to /etc/pureftpd.pwd .
  173. ------------------------ ENABLING VIRTUAL USERS ------------------------
  174. Of course, to use virtual users, you have to enable their support in the FTP
  175. server itself. At compile-time, this is done by giving --with-puredb to
  176. ./configure (--with-everything also enables it and binary packages have it
  177. compiled in) .
  178. Then, add this switch to your usual pure-ftpd switches:
  179. -l puredb:/path/to/puredb_file
  180. If long options are enabled, you can also use --login instead of -l .
  181. Let's run the server with automatic creation of home directories and puredb
  182. authentication:
  183. /usr/local/sbin/pure-ftpd -j -lpuredb:/etc/pureftpd.pdb &
  184. Try to 'ftp localhost' and log in as joe.
  185. ------------------------ CONVERTING SYSTEM ACCOUNTS ------------------------
  186. You can convert all system (/etc/passwd) accounts to virtual FTP users, with
  187. the "pure-pwconvert" tool.
  188. Just run it:
  189. pure-pwconvert >> /etc/pureftpd.passwd
  190. If you do it as a non-privileged user, passwords won't be filled in. If you
  191. do it as root, everything will be copied, even hashed passwords.
  192. Copying system accounts to FTP accounts makes sense, because that way, users
  193. can use different passwords for FTP and for Telnet access.
  194. ------------------------ ENVIRONNEMENT VARIABLES ------------------------
  195. If defined, a PURE_PASSWDFILE environment variable can set the default path
  196. to the pureftpd.passwd file. Without this variable, it defaults to
  197. /etc/pureftpd.passwd .
  198. If defined, a PURE_DBFILE environment variable can set the default path
  199. to the pureftpd.pdb file. Without this variable, it defaults to
  200. /etc/pureftpd.pdb .