1. 程式人生 > >contos安裝FTP服務

contos安裝FTP服務

reporting decimal 名稱 out idle spl col 郵件地址 hang

最近公司有一個內部比賽(黑客馬拉松),報名參加了這麽一個賽事,在準備參賽作品的同時(參賽服務器需要自己搭建),借著這個機會,決定把tomcat部署相關的知識從0到1重新捋一遍。就當備忘錄了。

FTP服務器(File Transfer Protocol Server)是在互聯網上提供文件存儲和訪問服務的計算機,它們依照FTP協議提供服務。 FTP是File Transfer Protocol(文件傳輸協議)。顧名思義,就是專門用來傳輸文件的協議。簡單地說,支持FTP協議的服務器就是FTP服務器。

本文適用範圍win10系統連接虛擬機contos, 博主使用的是filezilla連接contos。若是其他方式僅供參考。

v安裝vsftpd

? 檢查並安裝

確認虛擬機網絡連接方式

技術分享圖片

盡量虛擬機和實體機在同一IP段,如實體機:192.168.122.1 虛擬機則:192.168.122.9

確保實體機和虛擬機的ip可以互相ping通

先查看你是否安裝了vsftpd

rpm -q vsftpd

技術分享圖片

如上圖,則未安裝,若已安裝,則顯示例如 vsftpd-3.0.2-10.el7.x86_64

未安裝那就安裝vsftpd

yum install -y vsftpd

技術分享圖片

如上圖,需要root權限

su root

然後輸入密碼,如下圖,設置root權限成功

技術分享圖片

然後繼續安裝yum install -y vsftpd

安裝完畢,如下圖。

技術分享圖片

查看到安裝的目錄whereis vsftpd

技術分享圖片

vsftpd目錄為: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz

查看vsftpd服務的狀態systemctl status vsftpd.service

技術分享圖片

開啟vsftpd服務systemctl start vsftpd.service

開啟之後再查看vsftpd服務的狀態

技術分享圖片

設置vsftpd服務開機自啟systemctl enable vsftpd.service

技術分享圖片

v防火墻設置

防火墻添加FTP服務

systemctl enable firewalld

systemctl restart firewalld

firewall-cmd --permanent --zone=public --add-service=ftp

firewall-cmd --reload

firewall-cmd --reload

設置SELinux

getsebool -a | grep ftp

setsebool -P ftpd_full_access on

技術分享圖片

查看設置vi /etc/selinux/config

技術分享圖片

設置SELINUX=disabled

v配置vsftpd.conf

配置之前先備份cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak

配置vsftpd.conf文件vim /etc/vsftpd/vsftpd.conf 推薦使用vim方式,vi方式配置文件註釋和實體沒有顏色區分,會看花眼的。

技術分享圖片
# 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.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#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
#
# Activate logging of uploads/downloads.
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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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.
#
# 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().
# (Warning! chroot‘ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# 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=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then 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
View Code

中文版的(來源於網絡,侵權必刪):

技術分享圖片
# 是否允許匿名登錄FTP服務器,默認設置為YES允許
# 用戶可使用用戶名ftp或anonymous進行ftp登錄,口令為用戶的E-mail地址。
# 如不允許匿名訪問則設置為NO
anonymous_enable=YES
# 是否允許本地用戶(即linux系統中的用戶帳號)登錄FTP服務器,默認設置為YES允許
# 本地用戶登錄後會進入用戶主目錄,而匿名用戶登錄後進入匿名用戶的下載目錄/var/ftp/pub
# 若只允許匿名用戶訪問,前面加上#註釋掉即可阻止本地用戶訪問FTP服務器
local_enable=YES
# 是否允許本地用戶對FTP服務器文件具有寫權限,默認設置為YES允許
write_enable=YES 
# 掩碼,本地用戶默認掩碼為077
# 你可以設置本地用戶的文件掩碼為缺省022,也可根據個人喜好將其設置為其他值
#local_umask=022
# 是否允許匿名用戶上傳文件,須將全局的write_enable=YES。默認為YES
#anon_upload_enable=YES
# 是否允許匿名用戶創建新文件夾
#anon_mkdir_write_enable=YES 
# 是否激活目錄歡迎信息功能
# 當用戶用CMD模式首次訪問服務器上某個目錄時,FTP服務器將顯示歡迎信息
# 默認情況下,歡迎信息是通過該目錄下的.message文件獲得的
# 此文件保存自定義的歡迎信息,由用戶自己建立
#dirmessage_enable=YES
# 是否讓系統自動維護上傳和下載的日誌文件
# 默認情況該日誌文件為/var/log/vsftpd.log,也可以通過下面的xferlog_file選項對其進行設定
# 默認值為NO
xferlog_enable=YES
# Make sure PORT transfer connections originate from port 20 (ftp-data).
# 是否設定FTP服務器將啟用FTP數據端口的連接請求
# ftp-data數據傳輸,21為連接控制端口
connect_from_port_20=YES
# 設定是否允許改變上傳文件的屬主,與下面一個設定項配合使用
# 註意,不推薦使用root用戶上傳文件
#chown_uploads=YES
# 設置想要改變的上傳文件的屬主,如果需要,則輸入一個系統用戶名
# 可以把上傳的文件都改成root屬主。whoever:任何人
#chown_username=whoever
# 設定系統維護記錄FTP服務器上傳和下載情況的日誌文件
# /var/log/vsftpd.log是默認的,也可以另設其它
#xferlog_file=/var/log/vsftpd.log
# 是否以標準xferlog的格式書寫傳輸日誌文件
# 默認為/var/log/xferlog,也可以通過xferlog_file選項對其進行設定
# 默認值為NO
#xferlog_std_format=YES
# 以下是附加配置,添加相應的選項將啟用相應的設置
# 是否生成兩個相似的日誌文件
# 默認在/var/log/xferlog和/var/log/vsftpd.log目錄下
# 前者是wu_ftpd類型的傳輸日誌,可以利用標準日誌工具對其進行分析;後者是vsftpd類型的日誌
#dual_log_enable
# 是否將原本輸出到/var/log/vsftpd.log中的日誌,輸出到系統日誌
#syslog_enable
# 設置數據傳輸中斷間隔時間,此語句表示空閑的用戶會話中斷時間為600秒
# 即當數據傳輸結束後,用戶連接FTP服務器的時間不應超過600秒。可以根據實際情況對該值進行修改
#idle_session_timeout=600
# 設置數據連接超時時間,該語句表示數據連接超時時間為120秒,可根據實際情況對其個修改
#data_connection_timeout=120
# 運行vsftpd需要的非特權系統用戶,缺省是nobody
#nopriv_user=ftpsecure
# 是否識別異步ABOR請求。
# 如果FTP client會下達“async ABOR”這個指令時,這個設定才需要啟用
# 而一般此設定並不安全,所以通常將其取消
#async_abor_enable=YES
# 是否以ASCII方式傳輸數據。默認情況下,服務器會忽略ASCII方式的請求。
# 啟用此選項將允許服務器以ASCII方式傳輸數據
# 不過,這樣可能會導致由"SIZE /big/file"方式引起的DoS攻擊
#ascii_upload_enable=YES
#ascii_download_enable=YES
# 登錄FTP服務器時顯示的歡迎信息
# 如有需要,可在更改目錄歡迎信息的目錄下創建名為.message的文件,並寫入歡迎信息保存後
#ftpd_banner=Welcome to blah FTP service.
# 黑名單設置。如果很討厭某些email address,就可以使用此設定來取消他的登錄權限
# 可以將某些特殊的email address抵擋住。
#deny_email_enable=YES
# 當上面的deny_email_enable=YES時,可以利用這個設定項來規定哪些郵件地址不可登錄vsftpd服務器
# 此文件需用戶自己創建,一行一個email address即可
#banned_email_file=/etc/vsftpd/banned_emails
# 用戶登錄FTP服務器後是否具有訪問自己目錄以外的其他文件的權限
# 設置為YES時,用戶被鎖定在自己的home目錄中,vsftpd將在下面chroot_list_file選項值的位置尋找chroot_list文件
# 必須與下面的設置項配合
#chroot_list_enable=YES
# 被列入此文件的用戶,在登錄後將不能切換到自己目錄以外的其他目錄
# 從而有利於FTP服務器的安全管理和隱私保護。此文件需自己建立
#chroot_list_file=/etc/vsftpd/chroot_list
# 是否允許遞歸查詢。默認為關閉,以防止遠程用戶造成過量的I/O
#ls_recurse_enable=YES
# 是否允許監聽。
# 如果設置為YES,則vsftpd將以獨立模式運行,由vsftpd自己監聽和處理IPv4端口的連接請求
listen=YES
# 設定是否支持IPV6。如要同時監聽IPv4和IPv6端口,
# 則必須運行兩套vsftpd,采用兩套配置文件
# 同時確保其中有一個監聽選項是被註釋掉的
#listen_ipv6=YES
# 設置PAM外掛模塊提供的認證服務所使用的配置文件名,即/etc/pam.d/vsftpd文件
# 此文件中file=/etc/vsftpd/ftpusers字段,說明了PAM模塊能抵擋的帳號內容來自文件/etc/vsftpd/ftpusers中
#pam_service_name=vsftpd
# 是否允許ftpusers文件中的用戶登錄FTP服務器,默認為NO
# 若此項設為YES,則user_list文件中的用戶允許登錄FTP服務器
# 而如果同時設置了userlist_deny=YES,則user_list文件中的用戶將不允許登錄FTP服務器,甚至連輸入密碼提示信息都沒有
#userlist_enable=YES/NO
# 設置是否阻扯user_list文件中的用戶登錄FTP服務器,默認為YES
#userlist_deny=YES/NO
# 是否使用tcp_wrappers作為主機訪問控制方式。
# tcp_wrappers可以實現linux系統中網絡服務的基於主機地址的訪問控制
# 在/etc目錄中的hosts.allow和hosts.deny兩個文件用於設置tcp_wrappers的訪問控制
# 前者設置允許訪問記錄,後者設置拒絕訪問記錄。
# 如想限制某些主機對FTP服務器192.168.57.2的匿名訪問,編緝/etc/hosts.allow文件,如在下面增加兩行命令:
# vsftpd:192.168.57.1:DENY 和vsftpd:192.168.57.9:DENY
# 表明限制IP為192.168.57.1/192.168.57.9主機訪問IP為192.168.57.2的FTP服務器
# 此時FTP服務器雖可以PING通,但無法連接
tcp_wrappers=YES
View Code

編輯user_list文件,vim /etc/vsftpd/user_list 允許test用戶訪問FTP 註意下圖中默認UsRistListDebug的設置。

默認情況下可以不編輯user_list文件。

技術分享圖片

按步驟操作以後,效果如下:

技術分享圖片

filezilla效果圖如下:

技術分享圖片

v註意事項

  • 確保關閉防火墻systemctl stop firewalld(臨時關閉)或者systemctl disable firewalld(禁止開機啟動)
  • 查看是否安裝telnetrpm -qa | grep telnet
  • 最好安裝telnetyum install telnet-server

FTP數字代碼的意義

技術分享圖片
110 重新啟動標記應答。
120 服務在多久時間內ready。
125 數據鏈路端口開啟,準備傳送。
150 文件狀態正常,開啟數據連接端口。
200 命令執行成功。
202 命令執行失敗。
211 系統狀態或是系統求助響應。
212 目錄的狀態。
213 文件的狀態。
214 求助的訊息。
215 名稱系統類型。
220 新的聯機服務ready。
221 服務的控制連接端口關閉,可以註銷。
225 數據連結開啟,但無傳輸動作。
226 關閉數據連接端口,請求的文件操作成功。
227 進入passive mode。
230 使用者登入。
250 請求的文件操作完成。
257 顯示目前的路徑名稱。
331 用戶名稱正確,需要密碼。
332 登入時需要賬號信息。
350 請求的操作需要進一部的命令。
421 無法提供服務,關閉控制連結。
425 無法開啟數據鏈路。
426 關閉聯機,終止傳輸。
450 請求的操作未執行。
451 命令終止:有本地的錯誤。
452 未執行命令:磁盤空間不足。
500 格式錯誤,無法識別命令。
501 參數語法錯誤。
502 命令執行失敗。
503 命令順序錯誤。
504 命令所接的參數不正確。
530 未登入。 
532 儲存文件需要賬戶登入。
550 未執行請求的操作。
551 請求的命令終止,類型未知。
552 請求的文件終止,儲存位溢出。 
553 未執行請求的的命令,名稱不正確。
View Code

contos安裝FTP服務