yum install vsftpd
chkconfig vsftpd on
service vsftpd start
With default settings, it will allow users who have accounts in the system to log in with their passwords.
! Anonymous logins are allowed by default!
You can change the default behavior to authorize not only system users but also users from a special list. Formally, they will then operate under a specified user, such as ftpuser.
Remember that this is configured via PAM, in /etc/pam.d/vsftpd
The default file:
#%PAM-1.0
session optional pam_keyinit.so force revoke
auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth required pam_shells.so
auth include system-auth
account include system-auth
session include system-auth
session required pam_loginuid.so
BDB
For authorization via db, it is better to create a separate file and specify it in the configuration.
/etc/pam.d/vsftpd-db
Select the PAM configuration via pam_service_name=vsftpd-db
session optional pam_keyinit.so force revoke
auth required /lib64/security/pam_userdb.so debug db=/etc/vsftpd/login
account required /lib64/security/pam_userdb.so debug db=/etc/vsftpd/login
In this case, the password file will be located at /etc/vsftpd/login.db
Format of the original file (login.txt):
user1
password1
user2
password2
(newline at the end. Without it, it may not work!)
Generating the password file:
db_load -T -t hash -f login.txt /etc/vsftpd/login.db
Via MySQL
Install pam_mysql
/etc/pam.d/vsftpd-mysql
auth required pam_mysql.so user=vsftpd passwd=ftpdpass host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2 account required pam_mysql.so user=vsftpd passwd=ftpdpass host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2
Test MySQL functionality, add the database and user
CREATE DATABASE vsftpd;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO 'vsftpd'@'localhost' IDENTIFIED BY 'ftpdpass';
FLUSH PRIVILEGES;
Create the table:
CREATE TABLE 'accounts' ( 'id' INT NOT NULL AUTO_INCREMENT PRIMARY KEY , 'username' VARCHAR(30) NOT NULL , 'pass' VARCHAR( 50 ) NOT NULL , UNIQUE ( 'username' ) ) ENGINE = MYISAM ;
quit;
Add a system user
vsftpd:*:1003:1003:User &:/home/vsftpd:/sbin/nologin
Add a user
#mysql -u root
USE vsftpd;
INSERT INTO accounts (username, pass) VALUES(’testuser’, PASSWORD(’secret’));
quit;
_______________________________________________________
the problem I encountered: cannot change directory:/home/username
By default, SELinux is enabled, which causes the problem. It can be fixed by
setsebool -P ftp_home_dir 1
And by adding one line to "vsftpd.conf":
session_support=YES
service vsftpd restart
The problem occurs because vsftpd does not touch the session service modules in PAM by default.
http://www.opennet.ru/base/net/vsftpd_overview.txt.html detailed article on this topic
