1. 程式人生 > >vsftpd的搭建 centos6.5

vsftpd的搭建 centos6.5

install actual unp erl markdown string accept sage sco

1.安裝

(1) rpm -qa | grep vsftpd查看是否已經安裝
(2) yum -y install vsftpd
(3) 默認配置文件在/etc/vsftpd/vsftpd.conf

2.創建虛擬用戶

(1) 創建ftp文件夾  mkdir ftpfile 例如 /ftpfile
(2) 添加匿名用戶 : useradd ftpuser -d /ftpfile -s /sbin/nologin  (用戶沒有登陸linux的權限)
(3) 修改ftpfile權限:  chown -R  ftpuser.ftpuser /ftpfile
(4) 重設ftpuser密碼: passwd ftpuser

3.配置

(1) cd /etc/vsftpd
(2) sudo vim chroot_list (以前沒有)
(3) 把剛才新增的虛擬用戶添加到此配置文件中,後續要引用
(4) sudo vim /etc/selinux/config,修改SELINUX=disabled  
註意:如果一會驗證時遇到550拒絕訪問執行: sudo setsebool -P ftp_home_dir 1
(5) 配置/etc/vsftpd/vsftpd.conf

4.vsftp配置參數介紹

本項目要用到的配置項:
1)local_root=/ftpfile(當本地用戶登入時,將被更換到定義的目錄下,默認值為各用戶的家目錄) 
2)anon_root=/ftpfile(使用匿名登入時,所登入的目錄) 
3)use_localtime=YES(默認是GMT時間,改成使用本機系統時間)
4)anonymous_enable=NO(不允許匿名用戶登錄)
5)local_enable=YES(允許本地用戶登錄)
6)write_enable=YES(本地用戶可以在自己家目錄中進行讀寫操作)
7)local_umask=022(本地用戶新增檔案時的umask值)
8)dirmessage_enable=YES(如果啟動這個選項,那麽使用者第一次進入一個目錄時,會檢查該目錄下是否有.message這個檔案,如果有,則會出現此檔案的內容,通常這個檔案會放置歡迎話語,或是對該目錄的說明。默認值為開啟)
9)xferlog_enable=YES(是否啟用上傳/下載日誌記錄。如果啟用,則上傳與下載的信息將被完整紀錄在xferlog_file 所定義的檔案中。預設為開啟。)
10)connect_from_port_20=YES(指定FTP使用20端口進行數據傳輸,默認值為YES)
11)xferlog_std_format=YES(如果啟用,則日誌文件將會寫成xferlog的標準格式)
12)ftpd_banner=Welcome to mmall FTP Server(這裏用來定義歡迎話語的字符串)
13)chroot_local_user=NO(用於指定用戶列表文件中的用戶是否允許切換到上級目錄)
14)chroot_list_enable=YES(設置是否啟用chroot_list_file配置項指定的用戶列表文件)
15)chroot_list_file=/etc/vsftpd/chroot_list(用於指定用戶列表文件)
16)listen=YES(設置vsftpd服務器是否以standalone模式運行,以standalone模式運行是一種較好的方式,此時listen必須設置為YES,此為默認值。建議不要更改,有很多與服務器運行相關的配置命令,需要在此模式下才有效,若設置為NO,則vsftpd不是以獨立的服務運行,要受到xinetd服務的管控,功能上會受到限制)
17)pam_service_name=vsftpd(虛擬用戶使用PAM認證方式,這裏是設置PAM使用的名稱,默認即可,與/etc/pam.d/vsftpd對應) userlist_enable=YES(是否啟用vsftpd.user_list文件,黑名單,白名單都可以
18)pasv_min_port=61001(被動模式使用端口範圍最小值)
19)pasv_max_port=62000(被動模式使用端口範圍最大值)
20)pasv_enable=YES(pasv_enable=YES/NO(YES)
若設置為YES,則使用PASV工作模式;若設置為NO,則使用PORT模式。默認值為YES,即使用PASV工作模式。
   FTP協議有兩種工作方式:PORT方式和PASV方式,中文意思為主動式和被動式。
   一、PORT(主動)方式的連接過程是:客戶端向服務器的FTP端口(默認是21)發送連接請求,服務器接受連接,建立一條命令鏈路。 
  當需要傳送數據時,客戶端在命令鏈路上用 PORT命令告訴服務器:“我打開了****端口,你過來連接我”。於是服務器從20端口向客戶端的****端口發送連接請求,建立一條數據鏈路來傳送數據。
   二、PASV(被動)方式的連接過程是:客戶端向服務器的FTP端口(默認是21)發送連接請求,服務器接受連接,建立一條命令鏈路。 
  當需要傳送數據時,服務器在命令鏈路上用 PASV命令告訴客戶端:“我打開了****端口,你過來連接我”。於是客戶端向服務器的****端口發送連接請求,建立一條數據鏈路來傳送數據。 
  從上面可以看出,兩種方式的命令鏈路連接方法是一樣的,而數據鏈路的建立方法就完全不同。而FTP的復雜性就在於此。
)

5.防火墻的配置

vim /etc/sysconfig/iptables

添加下面的配置
#vsftpd
-A INPUT  -p TCP --dport 61001:62000 -j ACCEPT
-A OUTPUT  -p TCP --sport 61001:62000 -j ACCEPT
-A INPUT -p TCP --dport 20 -j ACCEPT
-A OUTPUT  -p TCP --sport 20 -j ACCEPT
-A INPUT  -p TCP --dport 21 -j ACCEPT
-A OUTPUT -p TCP --sport 21 -j ACCEPT

重啟防火墻:
sudo service iptables restart

6.vsftpd.conf

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd‘s
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
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
#
# 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
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service.


local_root=/home/ftpfile
anon_root=/home/ftpfile
use_localtime=yes


#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# 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
chroot_list_enable=YES
# (default follows)
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
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES


pasv_min_port=61001
pasv_max_port=62000

7.瀏覽器登陸

ftp://121.42.165.99/

vsftpd的搭建 centos6.5