VSFTP là một dịch vụ FTP server chạy trên linux, chúng ta sẽ dùng hệ thống VSFTP để có thể chia sẻ tài liệu (tài nguyên) cho người khác.
- Cài đặt vsftp
[vagrant@localhost ~]$ sudo yum install vsftp
Chúng ta cũng cần cài ftp client để test
sudo yum install ftp
để cấu hình cho vsftp được bật lúc khởi động hệ thống dùng lệnh sau
sudo chkconfig vsftpd on
Đến đây chúng ta đã có thể dùng ftp được rồi tuy nhiên việc dùng ftp sẽ xác thực bằng account của hệ thống và thư mục ftp mặc định sẽ là /home/tênuser
Để truy cập ftp server có 2 cách thứ nhất truy cập trực tiếp bằng web
fttp://172.16.x.x
hoặc qua lệnh
ftp 172.16.x.x
Để cấu hình nhiều account và mỗi account mỗi thư mục khác nhau sau đây mình sẽ hướng dẫn cài đặt và config vitual user cho vsftp
2. Cài đặt Berkeley Database(db4)
sudo yum install db4-utils db4 -y
Tiếp theo ta tạo file data chứa thông tin account
sudo vi /home/login.txt
và thêm account
hientq
123456
trong đó username là hientq và password là 123456
Tiếp theo chạy command bên dưới để tạo db từ plain text file ở trên
sudo db_load -T -t hash -f /home/login.txt /etc/vsftpd/login.db
Create a PAM file
Bây giờ ta sẽ tạo một pam file để sử dụng db login.db ở trên
sudo vi /etc/pam.d/vsftpd_virtual
thêm nội dung như sau và lưu lại
#%PAM-1.0 auth required pam_userdb.so db=/etc/vsftpd/virtual_users account required pam_userdb.so db=/etc/vsftpd/virtual_users session required pam_loginuid.so
Tiếp đến ta sẽ sử file vsftp config
sudo vi /etc/vsftpd/vsftpd.conf
và sửa hoặc tạo mới một file như sau
# Allow anonymous FTP? (Beware – allowed by default if you comment this out).
anonymous_enable=NO# Uncomment this to allow local users to log in.
local_enable=YES## Enable virtual users
guest_enable=YES## Virtual users will use the same permissions as anonymous
virtual_use_local_privs=YES#
# Uncomment this to enable any form of FTP write command.
write_enable=YES## PAM file name
pam_service_name=vsftpd_virtual## Home Directory for virtual users
user_sub_token=$USER
local_root=/home/ftp/$USER# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES## Hide ids from user
hide_ids=YES
listen=YES
Tiếp theo ta tạo thư mục ftp cho account hientq ở trên
sudo mkdir -p /home/ftp/hientq
và khởi động lại vsftp
sudo service vsftpd restart
Đến đây ftp server đã được cài và config xong để test ta thực hiện như sau
[vagrant@localhost ftp]$ ftp 172.16.41.95
Connected to 172.16.41.95 (172.16.41.95).
220 (vsFTPd 2.2.2)
Name (172.16.41.95:vagrant): hientq
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
hoặc truy vập trực tiếp từ web
ftp://172.16.41.95/
cảm ơn bạn đã xem 🙂