日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ftp服务器搭建(离线安装vsftpd),配置

發布時間:2025/7/25 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ftp服务器搭建(离线安装vsftpd),配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.下載vsftp:http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64)

2.檢查是否已經安裝了vsftp

rpm -qa | grep vsftpd
如果沒有提示則說明沒有安裝
如果提示版本號則說明已經安裝

3.安裝vsftpd-3.0.2-22.el7.x86_64.rpm

離線安裝 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_64

解決:安裝相關依賴
rpm -ivh libcap-2.16-5.5.el6.x86_64.rpm
rpm -ivh libcap-devel-2.16-5.5.el6.x86_64.rpm

4.檢查是否安裝成功

[root@yjy-pt03 local]# rpm -qa | grep vsftpd vsftpd-2.2.2-24.el6.x86_64 //出現版本號,說明安裝成功

5.配置,這里只說能讓你的ftp跑起來的配置,詳細原理可以點擊查看這里

5.0 開啟vsftpd的兩個端口 20,21

開啟 # 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

?

5.1 創建兩個系統用戶

1.因為vsftpd默認的宿主用戶是root,不符合安全性要求,所以將新建立的vsftpd服務的宿主用戶的shell改為“ /sbin/nologin意思是禁止登錄系統 ”:

useradd vsftpd -s /sbin/nologin //系統用戶 vsftpd 主要是提供一個默認宿主

2.建立vsftpd虛擬宿主用戶:

useradd virtusers -s /sbin/nologin //系統用戶 virtusers 本文主要講虛擬用戶登錄,這相當于我們的虛擬用戶組

此次主要介紹虛擬用戶,顧名思義虛擬用戶在系統中是不純在的,它們集體寄托于方才創建的“virtusers”用戶,那么這個用戶就相當于一個虛擬用戶組了,因為這個用戶的權限將影響到后續講到的虛擬用戶。

5.2 配置vsftpd的主要配置文件vsftpd.conf

1.養成備份的好習慣

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

5.3.建立vsftpd的日志文件,并更改屬主為vsftpd的服務宿主用戶

//上線配置文件中配置的日志目錄
touch /var/log/vsftpd.logchown vsftpd.vsftpd /var/log/vsftpd.log

5.4?配置虛擬用戶

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

需要注意的是,以后對虛擬用戶的增刪操作完之后需要再次執行上述命令,使其生成新的數據文件。

5.5設置PAM驗證文件,并制定虛擬用戶數據庫文件進行讀取

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

5.6 為每一個虛擬賬戶配置專屬配置文件

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

2.建立虛擬用戶的倉庫目錄并更改相應屬主/組且賦予相應權限

mkdir -p /opt/vsftpd/file //這就是5.6中local_root=/opt/vsftpd/file 配置的根目錄 chown virtusers:virtusers /opt/vsftpd/file

chmod
755 /opt/vsftpd/file

3.隨便建立個文件方便后續檢測是否安裝成功:

touch /opt/vsftpd/file/abc

5.7重啟

service vsftpd restart

其他命令

#開啟
service vsftpd start #停止 service vsftpd stop #重啟 service vsftpd restart

?6.測試

打開文件夾輸入地址

會提示你登錄,或則右擊登錄

就可以看到你的文件夾了

7.附送:

博客:java操作vaftpd實現上傳、下載

gitHub源碼:https://github.com/UncleWW/Shop

轉載于:https://www.cnblogs.com/UncleWang001/p/9948150.html

總結

以上是生活随笔為你收集整理的ftp服务器搭建(离线安装vsftpd),配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。