1、安裝vsftpdhtml
1.1 檢查系統是否已經安裝過vsftpd了linux
1 [root@localhost /]# rpm -aq vsftpd
若是返回結果顯示:vim
1 vsftpd-3.0.2-21.el7.x86_64
#此處是查找vsftpd的返回結果
若是提示已安裝,可是你以前配置錯了,不知道怎麼搞,那麼進行1.2步驟服務器
1.2 卸載系統目前的vsftpdsession
中止vsftpd運行:app
1 [root@localhost /]# /sbin/service vsftpd stop
卸載vsftpdsocket
1 [root@localhost /]# rpm -e vsftpd-3.0.2-21.el7.x86_64
此時系統會返回如下信息async
1 warning: /etc/vsftpd/vsftpd.conf saved as /etc/vsftpd/vsftpd.conf.rpmsave
接下來直接把上步(系統返回的提示信息)沒卸載乾淨的東西刪除tcp
1 rm -rf /etc/vsftpd/vsftpd.conf.rpmsave
1.3 驗證vsftpd是否卸載乾淨ide
1 [root@localhost /]# /sbin/service vsftpd stop 2 Redirecting to /bin/systemctl stop vsftpd.service 3 Failed to stop vsftpd.service: Unit vsftpd.service not loaded. #找不到vsftpd 4 [root@localhost /]# /sbin/service vsftpd start 5 Redirecting to /bin/systemctl start vsftpd.service 6 Failed to start vsftpd.service: Unit not found. #找不到vsftpd
1.4 安裝vsftpd
1 [root@localhost /]# yum -y install vsftpd
1.5 啓動vsftpd
1 [root@localhost home]# systemctl start vsftpd.service
或者
1 [root@localhost home]# service vsftpd restart
1.6 開放端口
1 [root@localhost /]# firewall-cmd --zone=public --add-port=21/tcp --permanent 2 [root@localhost /]# firewall-cmd --reload
注意ftp是21端口,sftp是22端口,也能夠本身配置,可是到這一步,咱們只須要了解就行,咱們接着配置吧
2、分配用戶
2.1 在你的linux上新建一個用戶,只用來ftp不用來登陸服務器
1 useradd Marry -s /sbin/nologin -d /var/ftp
上面的意思是,新建一個不用來登陸服務器的用戶,Marry,並設置他的ftp空間爲/var/ftp 目錄下。
接下來配置用戶Marry的密碼:
1 passwd Marry #給Marry用戶設置密碼
接下來按照提示輸入你的密碼就好
回過頭來,說明下上面兩個命令的意思
1 /* useradd 使用到3個參數:用戶名,-s,-d,三個參數位置能夠變更 2 3 Marry是用戶名 4 5 -d 後面跟的是咱們要給予Marry的家目錄 6 7 */
2.2 設置上面新建用戶對文件夾的操做權限
修改/var/ftp的權限爲不可寫
1 [root@localhost vsftpd]# chmod a-w /var/ftp/
這是由於咱們在上面將/home/ftpuser/taotao文件的權限改成不可寫了,那麼咱們在這個目錄下建立一個images文件夾,用來上傳文件。並將權限賦值給 ftpuser 用戶
3、vsftpd配置
3.1 限制系統用戶鎖定在/home/ftpuser目錄
若是設置爲
chroot_local_user=YES chroot_list_enable=YES(這行能夠沒有, 也能夠有) chroot_list_file=/etc/vsftpd.chroot_list 那麼, 凡是加在文件vsftpd.chroot_list中的用戶都是不受限止的用戶 即, 能夠瀏覽其主目錄的上級目錄. 因此, 若是不但願某用戶可以瀏覽其主目錄上級目錄中的內容,能夠如上設置, 而後在 文件vsftpd.chroot_list中不添加該用戶便可(此時, 在該文件中的用戶都是能夠瀏覽其主目錄以外的目錄的). 或者, 設置以下 chroot_local_user=NO chroot_list_enable=YES(這行必需要有, 不然文件vsftpd.chroot_list不會起做用) chroot_list_file=/etc/vsftpd.chroot_list 而後把全部不但願有這種瀏覽其主目錄之上的各目錄權限的用戶添加到文件vsftpd.chroot_list(此時, 在該文件中的用戶都是不能夠瀏覽其主目錄以外的目錄的) 中便可(一行一個用戶名).
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf
這裏有兩種方案,我採用第二種,配置以下:
chroot_local_user=NO chroot_list_enable=YES #(這行必需要有, 不然文件vsftpd.chroot_list不會起做用) chroot_list_file=/etc/vsftpd/chroot_list
默認chroot_list是不存在的
[root@localhost vsftpd]# vim /etc/vsftpd/chroot_list
而後加入 ftpuser ,表示只有ftpuser不能訪問上級目錄,重啓vsftpd。
3.2 開啓PASV(被動模式)
在 /etc/vsftpd/vsftpd.conf 的最下面加入
1 pasv_enable=YES 2 pasv_min_port=30000 3 pasv_max_port=30999
(提示:若是你處於被動模式,發現登錄上了可是,沒法上下載數據,而且提示,沒法顯示,多是你防火牆的端口沒開,還有你的端口
pasv_min_port是最小的端口,
pasv_max_port是最大的端口,不要寫錯了,還有,端口開了,要重啓防火牆才能生效
)
而且在userlist_enable=YES文件後面添加
1 userlist_deny=NO 2 userlist_file=/etc/vsftpd/user_list
開啓防火牆:
[root@localhost taotao]# firewall-cmd --zone=public --add-port=30000-30999/tcp --permanent [root@localhost taotao]# firewall-cmd --reload
3.3 添加用戶到
添加用戶到chroot_list,等幾個文件中
4、最終的vsftpd.conf 文件的配置內容以下:
sz /etc/vsftpd/vsftpd.conf
1 # Example config file /etc/vsftpd/vsftpd.conf 2 # 3 # The default compiled in settings are fairly paranoid. This sample file 4 # loosens things up a bit, to make the ftp daemon more usable. 5 # Please see vsftpd.conf.5 for all compiled in defaults. 6 # 7 # READ THIS: This example file is NOT an exhaustive list of vsftpd options. 8 # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's 9 # capabilities. 10 # 11 # Allow anonymous FTP? (Beware - allowed by default if you comment this out). 12 anonymous_enable=YES 13 # 14 # Uncomment this to allow local users to log in. 15 # When SELinux is enforcing check for SE bool ftp_home_dir 16 local_enable=YES 17 # 18 # Uncomment this to enable any form of FTP write command. 19 write_enable=YES 20 # 21 # Default umask for local users is 077. You may wish to change this to 022, 22 # if your users expect that (022 is used by most other ftpd's) 23 local_umask=022 24 # 25 # Uncomment this to allow the anonymous FTP user to upload files. This only 26 # has an effect if the above global write enable is activated. Also, you will 27 # obviously need to create a directory writable by the FTP user. 28 # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access 29 #anon_upload_enable=YES 30 # 31 # Uncomment this if you want the anonymous FTP user to be able to create 32 # new directories. 33 #anon_mkdir_write_enable=YES 34 # 35 # Activate directory messages - messages given to remote users when they 36 # go into a certain directory. 37 dirmessage_enable=YES 38 # 39 # Activate logging of uploads/downloads. 40 xferlog_enable=YES 41 # 42 # Make sure PORT transfer connections originate from port 20 (ftp-data). 43 connect_from_port_20=YES 44 # 45 # If you want, you can arrange for uploaded anonymous files to be owned by 46 # a different user. Note! Using "root" for uploaded files is not 47 # recommended! 48 #chown_uploads=YES 49 #chown_username=whoever 50 # 51 # You may override where the log file goes if you like. The default is shown 52 # below. 53 #xferlog_file=/var/log/xferlog 54 # 55 # If you want, you can have your log file in standard ftpd xferlog format. 56 # Note that the default log file location is /var/log/xferlog in this case. 57 xferlog_std_format=YES 58 # 59 # You may change the default value for timing out an idle session. 60 #idle_session_timeout=600 61 # 62 # You may change the default value for timing out a data connection. 63 data_connection_timeout=120 64 # 65 # It is recommended that you define on your system a unique user which the 66 # ftp server can use as a totally isolated and unprivileged user. 67 #nopriv_user=ftpsecure 68 # 69 # Enable this and the server will recognise asynchronous ABOR requests. Not 70 # recommended for security (the code is non-trivial). Not enabling it, 71 # however, may confuse older FTP clients. 72 #async_abor_enable=YES 73 # 74 # By default the server will pretend to allow ASCII mode but in fact ignore 75 # the request. Turn on the below options to have the server actually do ASCII 76 # mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains 77 # the behaviour when these options are disabled. 78 # Beware that on some FTP servers, ASCII support allows a denial of service 79 # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd 80 # predicted this attack and has always been safe, reporting the size of the 81 # raw file. 82 # ASCII mangling is a horrible feature of the protocol. 83 ascii_upload_enable=YES 84 ascii_download_enable=YES 85 # 86 # You may fully customise the login banner string: 87 ftpd_banner=Welcome to blah FTP service. 88 # 89 # You may specify a file of disallowed anonymous e-mail addresses. Apparently 90 # useful for combatting certain DoS attacks. 91 #deny_email_enable=YES 92 # (default follows) 93 #banned_email_file=/etc/vsftpd/banned_emails 94 # 95 # You may specify an explicit list of local users to chroot() to their home 96 # directory. If chroot_local_user is YES, then this list becomes a list of 97 # users to NOT chroot(). 98 # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that 99 # the user does not have write access to the top level directory within the 100 # chroot) 101 chroot_local_user=YES 102 chroot_list_enable=YES 103 # (default follows) 104 chroot_list_file=/etc/vsftpd/chroot_list 105 # 106 # You may activate the "-R" option to the builtin ls. This is disabled by 107 # default to avoid remote users being able to cause excessive I/O on large 108 # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume 109 # the presence of the "-R" option, so there is a strong case for enabling it. 110 ls_recurse_enable=YES 111 # 112 # When "listen" directive is enabled, vsftpd runs in standalone mode and 113 # listens on IPv4 sockets. This directive cannot be used in conjunction 114 # with the listen_ipv6 directive. 115 listen=YES 116 # 117 # This directive enables listening on IPv6 sockets. By default, listening 118 # on the IPv6 "any" address (::) will accept connections from both IPv6 119 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 120 # sockets. If you want that (perhaps because you want to listen on specific 121 # addresses) then you must run two copies of vsftpd with two configuration 122 # files. 123 # Make sure, that one of the listen options is commented !! 124 #listen_ipv6=YES 125 126 pam_service_name=vsftpd 127 userlist_enable=YES 128 userlist_deny=NO 129 local_root=/var/public_home 130 tcp_wrappers=YES 131 use_localtime=YES 132 allow_writeable_chroot=YES 133 pasv_enable=YES 134 pasv_min_port=7666 135 pasv_max_port=7700
sz /etc/vsftpd/chroot_list
1 Bob 2 porter
sz /etc/vsftpd/user_list
1 # vsftpd userlist 2 # If userlist_deny=NO, only allow users in this file 3 # If userlist_deny=YES (default), never allow users in this file, and 4 # do not even prompt for a password. 5 # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers 6 # for users that are denied. 7 Bob 8 porter 9 root 10 bin 11 daemon 12 adm 13 lp 14 sync 15 shutdown 16 halt 17 mail 18 news 19 uucp 20 operator 21 games 22 nobody
sz /etc/vsftpd/ftpusers
1 # Users that are not allowed to login via ftp 2 root 3 bin 4 daemon 5 adm 6 lp 7 sync 8 shutdown 9 halt 10 mail 11 news 12 uucp 13 operator 14 games 15 nobody
之一FTP上傳,第一次能夠用「」「FlashFXP 5」,這個挺好用的
參考連接: