Advertisement
shokti

ubuntu server - pure-ftpd-mysql installation

Oct 2nd, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. requirement before install: LAMP installed in your system.
  2.  
  3. install pure-ftpd-mysql:
  4. sudo apt-get install pure-ftpd-mysql
  5.  
  6. create ftpgroup and ftpuser with 2001 id, change it if it is not available on your system:
  7. sudo groupadd -g 2001 ftpgroup
  8. sudo useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftpgroup ftpuser
  9.  
  10. ----------------------------------------------------------------------------------------------
  11.  
  12. login to phpmyadmin and run the sql script below to create the pureftpd database and grant it with privileges:
  13.  
  14. CREATE DATABASE pureftpd;
  15.  
  16. GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pureftpd'@'localhost' IDENTIFIED BY 'ftpdpass';
  17.  
  18. GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON pureftpd.* TO 'pureftpd'@'localhost.localdomain' IDENTIFIED BY 'ftpdpass';
  19.  
  20. FLUSH PRIVILEGES;
  21.  
  22. ----------------------------------------------------------------------------------------------
  23.  
  24. select the pureftpd database in the phpmyadmin and run the script below to create the ftpd table that will store the ftp user account:
  25.  
  26. CREATE TABLE ftpd (
  27. User varchar(16) NOT NULL default '',
  28. status enum('0','1') NOT NULL default '0',
  29. Password varchar(64) NOT NULL default '',
  30. Uid varchar(11) NOT NULL default '-1',
  31. Gid varchar(11) NOT NULL default '-1',
  32. Dir varchar(128) NOT NULL default '',
  33. ULBandwidth smallint(5) NOT NULL default '0',
  34. DLBandwidth smallint(5) NOT NULL default '0',
  35. comment tinytext NOT NULL,
  36. ipaccess varchar(15) NOT NULL default '*',
  37. QuotaSize smallint(5) NOT NULL default '0',
  38. QuotaFiles int(11) NOT NULL default 0,
  39. PRIMARY KEY (User),
  40. UNIQUE KEY User (User)
  41. ) ENGINE=MyISAM;
  42.  
  43. ----------------------------------------------------------------------------------------------
  44.  
  45. edit pure-ftpd-mysql config file:
  46. sudo nano /etc/pure-ftpd/db/mysql.conf
  47.  
  48. make sure that the value below is the same and uncommented. change MYSQLUser and MYSQLPassword value with the actual mysql user account in your system:
  49.  
  50. MYSQLSocket /var/run/mysqld/mysqld.sock
  51. MYSQLUser pureftpd
  52. MYSQLPassword ftpdpass
  53. MYSQLDatabase pureftpd
  54. MYSQLCrypt md5
  55. MYSQLGetPW SELECT Password FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  56. MYSQLGetUID SELECT Uid FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  57. MYSQLGetGID SELECT Gid FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  58. MYSQLGetDir SELECT Dir FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  59. MySQLGetBandwidthUL SELECT ULBandwidth FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  60. MySQLGetBandwidthDL SELECT DLBandwidth FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  61. MySQLGetQTASZ SELECT QuotaSize FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  62. MySQLGetQTAFS SELECT QuotaFiles FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
  63.  
  64. --------------------------------------------------------------------------------------------
  65.  
  66. This will make PureFTPd chroot every virtual user in his home directory so he will not be able to browse directories and files outside his home directory:
  67. sudo nano /etc/pure-ftpd/conf/ChrootEveryone
  68. put yes text value on the file and save.
  69.  
  70. This will make PureFTPd create a user's home directory if the home directory does not exist yet when the user login:
  71. sudo nano /etc/pure-ftpd/conf/CreateHomeDir
  72. put yes text value on the file and save.
  73.  
  74. restart pure-ftpd:
  75. sudo /etc/init.d/pure-ftpd-mysql restart
  76.  
  77. --------------------------------------------------------------------------------------------
  78.  
  79. Whenever you want to create a new user, you have to create an entry in the table ftpd so I will explain the columns of this table here:
  80.  
  81. a. User: The name of the virtual PureFTPd user (e.g. exampleuser).
  82. b. status: 0 or 1. 0 means the account is disabled, the user cannot login.
  83. c. Password: The password of the virtual user. Make sure you use MySQL's MD5 function to save the password encrypted as an MD5 string:
  84. d. UID: The userid of the ftp user you created at the end of step two (e.g. 2001).
  85. e. GID: The groupid of the ftp group you created at the end of step two (e.g. 2001).
  86. f. Dir: The home directory of the virtual PureFTPd user (e.g. /home/www.example.com). If it does not exist, it will be created when the new user logs in the first time via FTP. The virtual user will be jailed into this home directory, i.e., he cannot access other directories outside his home directory.
  87. g. ULBandwidth: Upload bandwidth of the virtual user in KB/sec. (kilobytes per second). 0 means unlimited.
  88. h. DLBandwidth: Download bandwidth of the virtual user in KB/sec. (kilobytes per second). 0 means unlimited.
  89. i. comment: You can enter any comment here (e.g. for your internal administration) here. Normally you leave this field empty.
  90. j. ipaccess: Enter IP addresses here that are allowed to connect to this FTP account. * means any IP address is allowed to connect.
  91. k. QuotaSize: Storage space in MB (not KB, as in ULBandwidth and DLBandwidth!) the virtual user is allowed to use on the FTP server. 0 means unlimited.
  92. l. QuotaFiles: amount of files the virtual user is allowed to save on the FTP server. 0 means unlimited.
  93.  
  94. --------------------------------------------------------------------------------------------
  95.  
  96. you can create user using phpmyadmin and enter user account information manually or run the script below:
  97.  
  98. INSERT INTO `ftpd` (`User`, `status`, `Password`, `Uid`, `Gid`, `Dir`, `ULBandwidth`, `DLBandwidth`, `comment`, `ipaccess`, `QuotaSize`, `QuotaFiles`) VALUES ('exampleuser', '1', MD5('secret'), '2001', '2001', '/home/www.example.com', '100', '100', '', '*', '50', '0');
  99.  
  100. --------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement