使用vsftpd 在ubuntu環境中搭建ftp服務器。。Vsftp 是一個專門爲unix類型系統設計一個ftp服務器,如linux。
Vsftpd 支持ipv6和ssl。支持explicit 和implicit FTPS(不是SFTP)。
vsftp是Ubuntu, CentOS, Fedora, NimbleX, Slackware,RHEL Linux 系統的默認ftp服務器.php
ubuntu16.04.1 x86_64 GNU/Linux
測試工具:FileZilla 3.36.0
**linux
**
3.1. 安裝vsftpd
sudo apt-get install vsftpd
vsftp安裝好後會自動生成ftp user和ftp groupubuntu
3.2. 備份配置文件
vsftpd的配置文件位於/etc/vsftpd.conf
修改以前按需求備份一個原文件。
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.original服務器
3.3. 部分配置文件內容介紹ssh
3.3.1. 匿名用戶登錄ide
是否容許匿名用戶登錄ftp,默認YES,只容許Anonymous用戶下載工具
# Allow anonymous FTP? (Disabled by default). anonymous_enable=NO
3.3.2. 本地用戶登錄測試
爲了容許在/etc/passwd內部用戶登錄ftp,需將此項設置爲YESui
# Uncomment this to allow local users to log in. local_enable=YES
3.3.3. 上傳設置this
若需對系統進行讀寫操做,需將此項設置爲YES
# Uncomment this to enable any form of FTP write command.
write_enable=YES
3.3.4. Chroot jail
#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(). # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that # the user does not have write access to the top level directory within the # chroot) chroot_local_user=YES chroot_list_enable=YES # (default follows) chroot_list_file=/etc/vsftpd.chroot_list
這是個頗有趣的變量,這個就是爲了配置是否運行ftp用戶離開其默認目錄。設置以前,需手動添加vsftpd.chroot_list文件,此文件內存儲ftp用戶,其表明的含義根據chroot_local_user和chroot_list_enable不一樣而不一樣。
此處將兩項均設置爲YES,並將但願有全部目錄訪問權限的ftp用戶存於vsftpd.chroot_list文件中。
3.3.5. 阻止用戶登錄
能夠經過設置阻止部分用戶訪問ftp服務器。配置以下:
userlist_enable=YES userlist_file=/etc/vsftpd.user_list userlist_deny=NO
手動添加此三項到配置文件,同時建立vsftpd.user_list。與chroot jail配置參數類似,不一樣的設置致使不一樣的效果
3.3.6. pam_service_name
pam_service_name參數用戶配置虛擬ftp用戶,需將此項設置爲ftp,不然可能會出現530 Login incorrect登錄失敗錯誤。
# This string is the name of the PAM service vsftpd will use. #pam_service_name=vsftpd pam_service_name=ftp
3.3.7. 鏈接數量限制
將下列配置信息添加到vsftpd文件內
local_max_rate=1000000 # Maximum data transfer rate in bytes per second max_clients=50 # Maximum number of clients that may be connected max_per_ip=2 # Maximum connections per IP
3.3.8. 其餘設置
顯示隱藏文件
# Show hidden files and the "." and ".." folders. # Useful to not write over hidden files: force_dot_files=YES
隱藏文件全部者信息
# Hide the info about the owner (user and group) of the files. hide_ids=YES
3.4. 重啓vsftpd服務
經過重啓vsftpd應用配置修改,重啓服務有如下三種方式
1) sudo service vsftpd restart
2) sudo systemctl restart vsftpd.service
3) sudo /etc/init.d/vsftpd restart
3.5. FTP用戶建立
useradd myusername
會在/home/路徑下建立一個與用戶名相同的文件夾,做爲用戶默認路徑。可以使用useradd –d [directory] myusername選項在建立時指定默認路徑,也可以使用usermod –d [directory] myusername 從新指定用戶默認路徑。
在建立用戶時,可使用命令sudo usermod –s /usr/sbin/nologin myusername 來禁止ssh登錄ftp用戶
建立完成後,便可使用ftp工具進行鏈接。
4.1. 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()
若將新建ftp用戶路徑指定到root路徑下,如/var/www/ftp,在鏈接時可能會報500 OOPS: vsftpd: refusing to run with writable root inside chroot () 錯誤。解決方法有兩種:
一、 使用 sudo chmod –R a-w [directory] 去除可寫權限,採用此方法會失去上傳功能
二、 在vsftpd.conf配置文件中添加allow_writeable_chroot=YES
4.2. 550 Access is denied
在進行上傳操做時可能會遇到550訪問被拒絕錯誤,此時須要查看上傳路徑是否給ftp用戶提供了寫入權限。
可能涉及到的命令:
1) 將myusername 用戶加入另外一個用戶組
usermod –a –G theothergroupname myusername
2) 將全部文件夾權限設置爲755(drwxr-xr-x)
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
3) 將全部文件權限設置爲644(-rw-r--r--)
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
**
**
[1]. Howto: Easy FTP with vsftpd, https://ubuntuforums.org/show...
[2]. Very Secure FTP Daemon , https://wiki.archlinux.org/in...
[3]. vsftpd 配置:chroot_local_user與chroot_list_enable詳解, https://blog.csdn.net/bluishg...
[4]. How do I set chmod for a folder and all of its subfolders and files?, https://stackoverflow.com/que...