VSFTP配置<一> ------ 匿名用戶與系統用戶配置詳解

簡介:

    安全性是編寫VSFTP的初衷,除了這與生俱來的安全特性以外,高速與高穩定性也是VSFTP的兩個重要特點。

    在速度方面,使用ASCII代碼的模式下載數據時,VSFTP的速度是Wu-FTP的兩倍,如果Linux主機使用2.4.*的內核,在千兆以太網上的下載速度可達86MB/S。

    在穩定方面,VSFTP就更加的出色,VSFTP在單機(非集羣)上支持4000個以上的併發用戶同時連接,根據Red Hat的Ftp服務器的數據,VSFTP服務器可以支持15000個併發用戶


實驗環境:

    OS:    CentOS 6.6
    vsftp:    vsftpd-2.2.2-12.el6_5.1.x86_64

一、vsftpd的安裝
    1、vsftp可以下載rpm安裝 也可以使用官方CD.iso 配置本地配置yum源進行安裝
[root@1inux htdocs]# yum -y install vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-12.el6_5.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================================
 Package                        Arch                           Version                                  Repository                  Size
=========================================================================================================================================
Installing:
 vsftpd                         x86_64                         2.2.2-12.el6_5.1                         CD                         151 k
Transaction Summary
=========================================================================================================================================
Install       1 Package(s)
Total download size: 151 k
Installed size: 331 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vsftpd-2.2.2-12.el6_5.1.x86_64                                                                                        1/1 
  Verifying  : vsftpd-2.2.2-12.el6_5.1.x86_64                                                                                        1/1 
Installed:
  vsftpd.x86_64 0:2.2.2-12.el6_5.1                                                                                                       
Complete!
[root@1inux htdocs]#
    2、查看vsftp安裝後生成的文件:
[root@1inux htdocs]# rpm -ql vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd        //用戶認證配置文件
/etc/rc.d/init.d/vsftpd        //服務腳本
/etc/vsftpd        //配置文件目錄
/etc/vsftpd/vsftpd.conf        //配置文件
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/sbin/vsftpd        //主程序
.....
/var/ftp    //匿名訪問目錄
/var/ftp/pub

    3、安裝完成後啓動vsftp

[root@1inux htdocs]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@1inux htdocs]#
=========================
匿名登錄FTP   
    匿名登錄方式:
    (1)可以輸入用戶名ftp,密碼爲空,然後登陸
    (2) 用戶名、密碼都是anonymous
ftp> help   //CentOS ftp客戶端可以使用help命令獲取命令列表
!        debug        mdir        sendport    site
$        dir        mget        put        size
account        disconnect    mkdir        pwd        status
append        exit        mls        quit        struct
ascii        form        mode        quote        system
bell        get        modtime        recv        sunique
binary        glob        mput        reget        tenex
bye        hash        newer        rstatus        tick
case        help        nmap        rhelp        trace
cd        idle        nlist        rename        type
cdup        image        ntrans        reset        user
chmod        lcd        open        restart        umask
close        ls        prompt        rmdir        verbose
cr        macdef        passive        runique        ?
delete        mdelete        proxy        send
ftp>
主要命令介紹:
    ascii      以ascii碼傳輸數據
    binary     以二進制方式傳輸數據
    chmod      修改權限
    cd         切換目錄
    lcd        本地目錄切換
    delete     刪除文件
    get        下載
    put        上傳
    mget       一次下載多個
    mput       一次上傳多個
    pwd        顯示當前所在位置   
    bye        退出


二、Vsftp匿名訪問配置
注意:配置之前先對其配置文件進行備份,以防止造成無法挽回的損失
# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

1、禁止匿名用戶訪問:修改配置文件如下:

anonymous_enable=NO

[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): ftp
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.        //訪問失敗
ftp>
2、增加匿名用戶上傳權限
anon_upload_enable=YES    //啓用這一行


ftp> put fstab
local: fstab remote: fstab
227 Entering Passive Mode (172,16,66,82,148,217).
553 Could not create file.        
//還是提示無法創建, 這是因爲vsftp服務是以ftp用戶啓動的其對對/var/ftp目錄沒有寫權限
    解決方案:在/var/ftp/目錄下創建一個目錄更改其權限使ftp用戶對其有讀寫權限:
[root@1inux vsftpd]# mkdir /var/ftp/upload/
[root@1inux vsftpd]# cd /var/ftp/
[root@1inux ftp]# setfacl -m u:ftp:rwx upload/
[root@1inux ftp]# getfacl upload/
# file: upload/
# owner: root
# group: root
user::rwx
user:ftp:rwx
group::r-x
mask::rwx
other::r-x
接下來我們再上傳文件試試
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (172,16,66,82,201,178).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Aug 04  2014 pub
drwxrwxr-x    2 0        0            4096 May 01 20:43 upload
226 Directory send OK.
ftp> cd upload
250 Directory successfully changed.
ftp> lcd /etc
Local directory now /etc
ftp> put fstab
local: fstab remote: fstab
227 Entering Passive Mode (172,16,66,82,47,38).
150 Ok to send data.
226 Transfer complete.
1127 bytes sent in 0.000133 secs (8473.68 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (172,16,66,82,233,197).
150 Here comes the directory listing.
-rw-------    1 14       50           1127 May 01 20:52 fstab        //文件已經存在
226 Directory send OK.
ftp>
3、創建目錄:
    默認配置是禁止匿名用戶創建目錄的,可以通過修改配置文件更改:
anon_mkdir_write_enable=YES    //啓用這一行
然後保存,重新加載配置文件:
[root@1inux vsftpd]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@1inux vsftpd]#
在客戶端匿名登錄創建目錄anontest
ftp> mkdir anontest
257 "/upload/anontest" created        //提示創建成功
ftp> ls
227 Entering Passive Mode (172,16,66,82,41,121).
150 Here comes the directory listing.
drwx------    2 14       50           4096 May 01 21:02 anontest    //目錄已經存在
-rw-------    1 14       50           1127 May 01 20:52 fstab
226 Directory send OK.
ftp>
4、刪除文件或目錄
    默認配置中是無法刪除文件的,需要在配置文件中添加一行如下:
anon_other_write_enable=YES    

匿名登錄:
ftp> ls
227 Entering Passive Mode (172,16,66,82,233,251).
150 Here comes the directory listing.
drwx------    2 14       50           4096 May 01 21:02 anontest
-rw-------    1 14       50           1127 May 01 20:52 fstab
226 Directory send OK.
ftp> delete fstab        //刪除文件
250 Delete operation successful.
ftp> rmdir anontest        //刪除目錄
250 Remove directory operation successful.
ftp> ls
227 Entering Passive Mode (172,16,66,82,237,22).
150 Here comes the directory listing.
226 Directory send OK.
ftp>

三、本地用戶權限管理

1、使用系統用戶登陸: 【默認情況下使用系統用戶登陸,登陸後可以在其家目錄下任意創建、上傳刪除文件或目錄】
local_enable=YES    //默認此行啓用狀態
write_enable=YES    //寫權限默認開啓
local_umask=022        //控制FTP登陸後的權限

    1.1、在vsftp上面添加一個用戶:
[root@1inux vsftpd]# useradd admin
[root@1inux vsftpd]# passwd admin
Changing password for user admin.
New password: 
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@1inux vsftpd]#
    1.2、訪問
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (172,16,66,82,236,21).
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd        
257 "/home/admin"    //使用系統用戶登陸默認訪問的是其家目錄
ftp> lcd /root    //切換本地目錄
ftp> pwd
257 "/etc"
----------------------
2、禁止系統用戶訪問:
    2.1、修改配置文件:
    local_enable=NO
然後重新加載服務
[root@1inux vsftpd]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@1inux vsftpd]#
    2.1、訪問:
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): admin
530 This FTP server is anonymous only.
Login failed.        //輸入用戶名後 直接提示失敗
ftp>

3、鎖定系統用戶至其家目錄
chroot_local_user=YES    //啓用此行
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> lcd /etc
Local directory now /etc
ftp> ls
227 Entering Passive Mode (172,16,66,82,171,255).
150 Here comes the directory listing.
drwxr-xr-x    2 501      501          4096 May 01 21:24 abc
226 Directory send OK.
4、鎖定部分用戶至其家目錄,可以啓用以下行:
chroot_list_enable=YES    //啓用列表
chroot_list_file=/etc/vsftpd/chroot_list        //在此文件中的用戶都會被鎖定

    4.1、創建用戶:
[root@1inux vsftpd]# useradd centos
[root@1inux vsftpd]# echo "1" | passwd --stdin centos
[root@1inux vsftpd]# useradd fedora
[root@1inux vsftpd]# echo "1" | passwd --stdin fedora
[root@1inux vsftpd]#
    4.2、創建用戶列表
[root@1inux vsftpd]# vim chroot_list
[root@1inux vsftpd]# cat chroot_list 
centos
    4.3、重新加載配置文件
[root@1inux vsftpd]# service vsftpd reload
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
    4.4、登陸查看
1、以centos身份登陸
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): centos
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> 
2、以fedora身份 登陸
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): fedora
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/fedora"

四、其他簡單配置說明:
1、dirmessage_enable=YES        //目錄消息提示
在FTP要提示消息的目錄下新建文件:
    # vim .message
Hello, guest
How are you?
重載配置文件:# service vsftpd reload
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 (vsFTPd 2.2.2)
Name (172.16.66.82:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd upload
250-Hello, guest        //已經提示剛纔定義的消息
250-How are you?
250 Directory successfully changed.
ftp>
2、日誌相關
    xferlog_enable=YES    //是否打開傳輸日誌,默認開啓
    xferlog_std_format=YES    //傳輸日誌是否啓用標準格式
    xferlog_file=/var/log/xferlog    //日誌路徑,【前面兩個都得啓用】

3、上傳屬主是否改變
    #chown_uploads=YES    //當ftp上傳文件時,是否更改其屬主
    #chown_username=whoever    //將屬主更爲爲whoever 即系統上的用戶名

4、超時相關
    #idle_session_timeout=600    //空閒會話超時時長,超過將自動斷開
    #data_connection_timeout=120    //數據連接超時時長(即用戶上傳下載數據時,數據連接斷開後,ftp斷開的超時時長)

5、上傳下載格式
    #ascii_upload_enable=YES    //其否強制使用ascill上傳
    #ascii_download_enable=YES    //其否強制使用ascill下載

注:當上傳下載的是二進制文件時,強制使用ascill上傳下載會產生故障

6、ftp信息
#ftpd_banner=Welcome to blah FTP service.  //用戶登陸時是否顯示歡迎信息,可自定義
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 Welcome to blah FTP service.        //登陸時顯示
Name (172.16.66.82:root):


7、vsftpd使用pam完成用戶認證,其用到的pam配置文件

/etc/pam.d/vsftpd      //定義了用戶訪問vsftpd時用哪個模塊對用戶做認證
# cat /etc/pam.d/vsftpd 
%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      password-auth
account    include      password-auth
session    required     pam_loginuid.so
session    include      password-auth
-------------------
auth    //做認證用的
account    //檢查用戶賬號是否在有效期內
session    //
_______/etc/pam.d/vsftpd  ______________
auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
-------------------------------------------------------------------------------------------


/etc/vsftpd/ftpusers  存放拒絕訪問vsftp的用戶列表,用戶名一旦在此文件中出現,其將會被禁止訪問vsftp

eg:
服務器端:
[root@1inux vsftpd]# echo "admin" >> ftpusers 
[root@1inux vsftpd]# service vsftpd reload
客戶端:
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 Welcome to blah FTP service.
Name (172.16.66.82:root): admin
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.    //登陸失敗
ftp>


8、控制用戶列表文件

    /etc/vsftpd/user_list
    userlist_enable=YES    //是否啓用控制用戶登陸的列表文件
    userlist_deny=YES|NO    //是否拒絕用戶列表中用戶  默認是YES


eg1:
當userlist_deny=YES時,user_list文件就變成了黑名單,文件內的用戶都不允許登陸

在user_list中添加centos用戶
# echo "centos" >> /etc/vsftpd/user_list
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 Welcome to blah FTP service.
Name (172.16.66.82:root): centos
530 Permission denied.        //被拒絕訪問
Login failed.
ftp> 
------
eg2:
當userlist_deny=NO時,user_list文件就變成了白名單,只有user_list文件內的用戶才允許登陸
[root@1inux vsftpd]# cat user_list 
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
centos
[root@1inux vsftpd]# 
客戶端:
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 Welcome to blah FTP service.
Name (172.16.66.82:root): fedora
530 Permission denied.        //fedora 用戶直接被拒絕
Login failed.
ftp> bye
221 Goodbye.
[root@1inux ~]# ftp 172.16.66.82
Connected to 172.16.66.82 (172.16.66.82).
220 Welcome to blah FTP service.
Name (172.16.66.82:root): centos
331 Please specify the password.
Password:
230 Login successful.        //centos 用戶可以訪問
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

9、連接限制:
    max_clients:    最大併發連接數
    max_per_ip:    每個IP可同時發起的最大請求數
    

10、傳輸速率
    anon_max_rate:    匿名用戶的最大傳輸速率,單位:“字節/秒”
    local_max_rate:    本地用戶的最大傳輸速率


OK   虛擬用戶及系統用的的配置基本上就這麼些......歡迎補充


更多配置參數請參考: man vsftpd.conf


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章