1.下載vsftp:http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64)php
2.檢查是否已經安裝了vsftphtml
rpm -qa | grep vsftpd
若是沒有提示則說明沒有安裝
若是提示版本號則說明已經安裝
3.安裝vsftpd-3.0.2-22.el7.x86_64.rpmjava
離線安裝 rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm 在線安裝 yum install -y vsftp
安裝過程可能會報錯:
[root@yjy-pt01 vsftpd]# rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
warning: vsftpd-3.0.2-22.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
libc.so.6(GLIBC_2.14)(64bit) is needed by vsftpd-3.0.2-22.el7.x86_64
libc.so.6(GLIBC_2.15)(64bit) is needed by vsftpd-3.0.2-22.el7.x86_64linux
解決:安裝相關依賴
rpm -ivh libcap-2.16-5.5.el6.x86_64.rpm
rpm -ivh libcap-devel-2.16-5.5.el6.x86_64.rpm
4.檢查是否安裝成功git
[root@yjy-pt03 local]# rpm -qa | grep vsftpd vsftpd-2.2.2-24.el6.x86_64 //出現版本號,說明安裝成功
開啓 # iptables -I INPUT -i eth0 -p tcp --dport 20 -j ACCEPT # iptables -I OUTPUT -o eth0 -p tcp --sport 20 -j ACCEPT 保存 # /etc/rc.d/init.d/iptables save 重啓防火牆 # service iptables restart
1.由於vsftpd默認的宿主用戶是root,不符合安全性要求,因此將新創建的vsftpd服務的宿主用戶的shell改成「 /sbin/nologin意思是禁止登陸系統 」:github
useradd vsftpd -s /sbin/nologin //系統用戶 vsftpd 主要是提供一個默認宿主
2.創建vsftpd虛擬宿主用戶:shell
useradd virtusers -s /sbin/nologin //系統用戶 virtusers 本文主要講虛擬用戶登陸,這至關於咱們的虛擬用戶組
這次主要介紹虛擬用戶,顧名思義虛擬用戶在系統中是不純在的,它們集體寄託於方纔建立的「virtusers」用戶,那麼這個用戶就至關於一個虛擬用戶組了,由於這個用戶的權限將影響到後續講到的虛擬用戶。數據庫
1.養成備份的好習慣vim
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.backup.conf
2.vim /etc/vsftpd/vsftpd.conf安全
#默認的根目錄爲
#local_root=/var/ftp
#設置爲NO表明不容許匿名 anonymous_enable=NO #設定本地用戶能夠訪問,主要是虛擬宿主用戶,若是設爲NO那麼所欲虛擬用戶將沒法訪問。 local_enable=YES #能夠進行寫的操做 write_enable=YES #設定上傳文件的權限掩碼 local_umask=022 #禁止匿名用戶上傳 anon_upload_enable=NO #禁止匿名用戶創建目錄 anon_mkdir_write_enable=NO # 設定開啓目錄標語功能 dirmessage_enable=YES # 設定開啓日誌記錄功能 xferlog_enable=YES #設定端口20進行數據鏈接 connect_from_port_20=YES #設定禁止上傳文件更改宿主 chown_uploads=NO #設定vsftpd服務日誌保存路勁。注意:改文件默認不純在,需手動touch,且因爲這裏更改了vsftpd服務的宿主用戶爲手動創建的vsftpd,則必 須注意給予該用戶對日誌的讀取權限不然服務啓動失敗。 xferlog_file=/var/log/vsftpd.log //這個文件在後面步驟中會說起 #設定日誌使用標準的記錄格式 xferlog_std_format=YES #設定空閒連接超時時間,這裏使用默認/秒。 #idle_session_timeout=600 #設定最大鏈接傳輸時間,這裏使用默認,將具體數值留給每一個用戶具體制定,默認120/秒 data_connection_timeout=3600 #設定支撐vsftpd服務的宿主用戶爲手動創建的vsftpd用戶。注意:一旦更改宿主用戶,需一塊兒與該服務相關的讀寫文件的讀寫賦權問題. nopriv_user=vsftpd #設定支持異步傳輸的功能 #async_abor_enable=YES #設置vsftpd的登錄標語 ftpd_banner=hello 歡迎登錄
#是否將全部用戶限制在主目錄,YES爲啓用 NO禁用.(該項默認值是NO,即在安裝vsftpd後不作配置的話,ftp用戶是能夠向上切換到要目錄以外的)
chroot_local_user=NO //若是設置成YE會致使你用java代碼建立文件夾時失敗,由於他被限制在了宿主目錄
#禁止用戶登出本身的ftp主目錄 chroot_list_enable=NO #禁止用戶登錄ftp後使用ls -R 命令。該命令會對服務器性能形成巨大開銷,若是該項運行當多個用戶使用該命令會對服務器形成威脅。 ls_recurse_enable=NO #設定vsftpd服務工做在standalone模式下。所謂standalone模式就是該服務擁有本身的守護進程,在ps -A能夠看出vsftpd的守護進程名。若是 不想工做在standalone模式下,能夠選擇SuperDaemon模式,註釋掉便可,在該模式下vsftpd將沒有本身的守護進程,而是由超級守護進程Xinetd全權代理,>與此同時,vsftpd服務的許多功能,將得不到實現。 listen=YES #設定userlist_file中的用戶將不能使用ftp userlist_enable=YES #設定pam服務下的vsftpd驗證配置文件名。所以,PAM驗證將參考/etc/pam.d/下的vsftpd文件配置。 pam_service_name=vsftpd #設定支持TCPwrappers tcp_wrappers=YES #################################################如下是關於虛擬用戶支持的重要配置項目,默認.conf配置文件中是不包含這些項目的,需手動添加。 #啓用虛擬用戶功能 guest_enable=YES #指定虛擬的宿主用戶 guest_username=virtusers //virtusers就是咱們上面建立的系統用戶,做爲咱們的虛擬用戶組使用
#設定虛擬用戶的權限符合他們的宿主用戶
virtual_use_local_privs=YES
#設定虛擬用戶我的vsftp的配置文件存放路勁。這個被指定的目錄裏,將被存放每一個虛擬用戶個性的配置文件,注意的地方是:配置文件名必須 和虛擬用戶名相同。
user_config_dir=/etc/vsftpd/vconf //這是個目錄,是爲每個虛擬用戶配置單獨的權限使用,這裏咱們主要配置每一個用戶的單獨根目錄
#開啓每一個虛擬用戶有獨立的根目錄
chroot_local_user=YES
#禁止反向域名解析,如果沒有添加這個參數可能會出現用戶登錄較慢,或則客戶連接不上ftp的現象
reverse_lookup_enable=NO
//上線配置文件中配置的日誌目錄
touch /var/log/vsftpd.log chown vsftpd.vsftpd /var/log/vsftpd.log
1.創建虛擬用戶配置文件的存放路徑 【這個路徑就是上面配置文件末尾配置的路徑】
mkdir /etc/vsftpd/vconf/
2.)創建一個虛擬用戶名單文件,用來記錄虛擬用戶的帳號和密碼,格式爲:一行用戶名,一行密碼。不要有空格
vim /opt/vsftp/passwd
test 123456 test1 654321
3.生成虛擬用戶數據文件
db_load -T -t hash -f /opt/vsftp/passwd /opt/vsftp/passwd.db
須要注意的是,之後對虛擬用戶的增刪操做完以後須要再次執行上述命令,使其生成新的數據文件。
1.操做前記得備份的好習慣
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.backup
2.查看我已經配置的文件:cat /etc/pam.d/vsftpd 紅色部分爲新增,能夠看到目錄就是咱們配置的用戶名密碼
#%PAM-1.0 #####32位系統配置 #auth sufficient /lib/security/pam_userdb.so db=/etc/vsftpd/xnpasswd #account sufficient /lib/security/pam_userdb.so db=/etc/vsftpd/xnpasswd #####64位系統配置 auth sufficient /lib64/security/pam_userdb.so db=/opt/vsftp/passwd account sufficient /lib64/security/pam_userdb.so db=/opt/vsftp/passwd #以上兩條是手動添加的,內容是對虛擬用戶的安全和賬戶權限進行驗證。 #這裏的auth是指對用戶的用戶名口令進行驗證。 #這裏的accout是指對用戶的賬戶有哪些權限哪些限制進行驗證。 auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed auth required pam_shells.so auth include system-auth account include system-auth session include system-auth session required pam_loginuid.so
1.我是直接copy的主配置文件而後改的,內容以下
vim /etc/vsftpd/vconf/test //注意文件名 test與passwd中用戶名要保持一致
# 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). local_root=/opt/vsftpd/file //這裏是我配置的test用戶的根目錄 anonymous_enable=NO # # 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=NO # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. anon_mkdir_write_enable=NO #anno_other_writer_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=NO #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/vsftpd.log # # 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=vsftpd # # 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. # # 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=NO #chroot_list_enable=NO # (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 #guest_enable=YES #guest_username=virtusers #virtual_use_local_privs=YES #reverse_lookup_enable=NO
mkdir -p /opt/vsftpd/file //這就是5.6中local_root=/opt/vsftpd/file 配置的根目錄
chown virtusers:virtusers /opt/vsftpd/file
chmod 755 /opt/vsftpd/file
touch /opt/vsftpd/file/abc
service vsftpd restart
其餘命令
#開啓
service vsftpd start
#中止
service vsftpd stop
#重啓
service vsftpd restart
6.測試
打開文件夾輸入地址
會提示你登陸,或則右擊登陸
就能夠看到你的文件夾了
gitHub源碼:https://github.com/UncleWW/Shop