0. 關閉selinuxpython
永久性關閉(這樣須要重啓服務器後生效) sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 臨時性關閉(當即生效,可是重啓服務器後失效) setenforce 0 #設置selinux爲permissive模式(即關閉) setenforce 1 #設置selinux爲enforcing模式(即開啓)
1. 查看是否安裝linux
rpm -qa | grep vsftp
2. 安裝vsftpvim
yum install vsftpd -y
3. 修改主配置文件centos
# 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. # # 是否容許匿名登陸FTP服務器,默認設置爲YES(容許) anonymous_enable=NO # # 是否容許本地用戶登陸FTP服務器,默認設置爲YES(容許) local_enable=YES # # 是否容許用戶(匿名用戶、本地用戶)對FTP服務器具備寫權限,默認設置爲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) # 設置本地用戶的文件生成掩碼,默認爲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 # obviously need to create a directory writable by the FTP user. # 是否容許匿名用戶上傳文件,默認設置爲YES(容許)。 #anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. # 是否容許匿名用戶建立新文件夾。默認設置爲YES(容許) #anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. # 是否激活目錄歡迎信息功能,當用戶首次訪問服務器上的某個目錄時,FTP服務器將顯示歡迎信息。默認狀況下,歡迎信息是經過目錄下的.message文件得到的 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 # 在FTP服務器中設置歡迎登陸信息。當用戶登陸到FTP服務器後,會看到歡迎細信息「Welcome to blah FTP service.」 ftpd_banner=Welcome to blah FTP service # # 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. # 若是用戶在600秒內沒有命令操做,強制脫機,避免佔用資源 idle_session_timeout=600 # # You may change the default value for timing out a data connection. # 若是服務器和客戶端的數據鏈接已經成功創建,可是可能因爲線路問題致使在120秒內仍是沒法順利地完成數據的傳送,客戶端的鏈接就會被vsftpd強制剔除 #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. # 當設置爲YES時,表示容許使用ASCII方式上傳和下載文件 #ascii_upload_enable=YES #ascii_download_enable=YES # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. # # 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 #是否鎖定根目錄(只能在指定給本身的目錄下作爲根目錄) #每行寫FTP用戶名就行 chroot_list_enable=YES #容許寫入 #allow_writeable_chroot=YES # (default follows) # 鎖定FTP用戶在本身目錄下面,不寫入的話有可能會直接顯示根目錄! 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. # 當設置爲YES時,則vsftpd將以獨立模式運行,由vsftpd本身監聽和處理鏈接請求 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=NO時ftpusers文件中的用戶將禁止訪問FTP服務器。所以ftpusers文件又被稱爲「禁止使用vsftpd的用戶列表文件」 userlist_enable=YES # 當userlist_enable爲YES,userlist_deny爲NO時,FTP服務器僅容許user_list中的用戶訪問 # 當userlist_enable爲YES,userlist_deny爲YES時,ftpusers和user_list文件中的用戶均不能訪問FTP服務器 # userlist_deny tcp_wrappers=YES #用來存放每一個須要獨立的FTP用戶的配置 user_config_dir=/etc/vsftpd/userconfig #centos7 開啓 #allow_writeable_chroot=YES
備份原配置文件後直接複製便可,建立虛擬用戶服務器
vim /etc/vsftpd/chroot_list ftpuser
4. 指定用戶根目錄 session
mkdir /etc/vsftpd/userconfig echo local_root=/var/ftp/ftpuser > /etc/vsftpd/userconfig/ftpuser
5. 建立用戶app
useradd -s /sbin/nologin -g ftp ftpuser && echo 你的密碼 | passwd --stdin ftpuser
6. 建立用戶FTP所能管理的目錄socket
mkdir /var/ftp/ftpuser #把所建的目錄給相應的帳號主權限 chown -R ftpuser:ftp /var/ftp/ftpuser
7. 關閉防火牆async
# 注意linux的版本 # CentOs 6 # 查看防火牆是否開啓 service iptables status # 臨時關閉防火牆 servcie iptables stop # 永久性關閉防火牆 service iptables off # CentOs 7+ # 查看防火牆是否開啓 firewall-cmd --state #臨時關閉防火牆 systemctl stop firewalld.service #永久關閉防火牆(重啓生效) systemctl disable firewalld.service
8. 啓動VSFTP服務tcp
service vsftpd start