1. 程式人生 > >ubuntu 使用vsftpd 建立FTP服務(使用者名稱密碼登入,限制列出目錄)

ubuntu 使用vsftpd 建立FTP服務(使用者名稱密碼登入,限制列出目錄)

vsftpd介紹

vsftpd 是“very secure FTP daemon”的縮寫,安全性是它的一個最大的特點。vsftpd 是一個 UNIX 類作業系統上執行的伺服器的名字,它可以執行在諸如 Linux、BSD、Solaris、 HP-UNIX等系統上面,是一個完全免費的、開放原始碼的ftp伺服器軟體,支援很多其他的 FTP 伺服器所不支援的特徵。比如:非常高的安全性需求、頻寬限制、良好的可伸縮性、可建立虛擬使用者、支援IPv6、速率高等。
vsftpd是一款在Linux發行版中最受推崇的FTP伺服器程式。特點是小巧輕快,安全易用。

摘自百度百科-vsftpd

ubuntu 安裝 vsftpd

$ sudo apt-get install vsftpd

使用apt安裝即可。

配置vsftpd

備份vsftpd.config

$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig

編輯vsftpd.config

手動修改配置,根據下方的patch檔案改一下。

$ sudo vim /etc/vsftpd.config

但是既然做了程式設計師就要懶一點,能自動就自動好了將配置好的檔案與原始檔案使用diff 生成的patch 檔案,儲存到本地,用patch命令更新即可。

--- /etc/vsftpd.conf.orig   2018-02-08 13:39:05.983282023 +0800
+++ /etc/vsftpd.conf 2018-02-10 11:14:15.584088172 +0800 @@ -28,11 +28,11 @@ local_enable=YES # # Uncomment this to enable any form of FTP write command. -#write_enable=YES +write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) -#local_umask=022
+local_umask=022 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will @@ -67,11 +67,11 @@ # # You may override where the log file goes if you like. The default is shown # below. -#xferlog_file=/var/log/vsftpd.log +xferlog_file=/var/log/vsftpd.log # # If you want, you can have your log file in standard ftpd xferlog format. # Note that the default log file location is /var/log/xferlog in this case. -#xferlog_std_format=YES +xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 @@ -100,7 +100,7 @@ #ascii_download_enable=YES # # You may fully customise the login banner string: -#ftpd_banner=Welcome to blah FTP service. +ftpd_banner=Welcome Lincoln Linux FTP Service. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. @@ -120,9 +120,9 @@ # the user does not have write access to the top level directory within the # chroot) #chroot_local_user=YES -#chroot_list_enable=YES +chroot_list_enable=YES # (default follows) -#chroot_list_file=/etc/vsftpd.chroot_list +chroot_list_file=/etc/vsftpd.chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large @@ -142,7 +142,7 @@ secure_chroot_dir=/var/run/vsftpd/empty # # This string is the name of the PAM service vsftpd will use. -pam_service_name=vsftpd +pam_service_name=ftp # # This option specifies the location of the RSA certificate to use for SSL # encrypted connections. @@ -152,4 +152,8 @@ # # Uncomment this to indicate that vsftpd use a utf8 filesystem. -#utf8_filesystem=YES +utf8_filesystem=YES +userlist_enable=YES +userlist_deny=NO +userlist_file=/etc/vsftpd.user_list +allow_writeable_chroot=YES

懶得手動改,可以將上面的patch 檔案儲存到機器上,然後使用

$ cd /
$ sudo  patch -p0 < [patch檔案路徑]

這樣就將配置更新了。

建立登入使用者

#先建立ftp目錄
$ sudo mkdir /home/ftpdir
#新增使用者
$ sudo useradd -d /home/ftpdir -s /bin/bash ftpuser
#設定使用者密碼
$ sudo passwd ftpuser
#設定ftp目錄使用者許可權
$ sudo chown ftpuser:ftpuser /home/ftpdir

新增vsftpd 登入使用者

#新建檔案/etc/vsftpd.user_list,用於存放允許訪問ftp的使用者:
$ sudo touch /etc/vsftpd.user_list 
$ sudo vim /etc/vsftpd.user_list

在/etc/vsftpd.user_list中新增允許登入ftp 的使用者
ftpuser

新增vsftpd登入使用者對目錄樹的許可權

#新建檔案/etc/vsftpd.chroot_list,設定可列出、切換目錄的使用者:
$ sudo touch /etc/vsftpd.chroot_list 
$ sudo vim /etc/vsftpd.chroot_list

在/etc/vsftpd.chroot_list 設定可列出、切換目錄的使用者
ftpuser

重啟 vsftpd 服務

$ sudo service vsftpd restart

驗證ftp服務

這裡寫圖片描述