經過以前的幾篇文章,咱們都知道了如何配置PHP環境,也知道如何保護咱們的vps以及如何綁定多個域名建設多個網站。有時候咱們爲了讓咱們的朋友也能用咱們的vps建站又不想給他們太多權限,有時候咱們想要當個主機商賣賣虛擬空間過過癮又不想裝管理環境,那麼就想要裝個ftp服務器了。html
通過前面的教程,相信你們對管理vps的操做是比較熟悉了,這裏我就不在截圖了,安裝ftp服務器也是比較簡單的,相信你們能夠輕鬆學會。安全
一安裝環境服務器
1.先檢查有沒有安裝 rpm -q vsftpd
若是沒有安裝 yum install vsftpd session
2.先關閉防火牆進行調試. app
service iptables stop socket
或者一步到位 添加規則容許21端口通行
vi /etc/sysconfig/iptables async
添加一條
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT tcp
爲了讓FLASHFXP之類的軟件更好的鏈接服務器,得讓VSFTPD支持被動模式才行: ide
b.防火牆配置開放: 性能
-A INPUT -p tcp --dport 30000:30100 -j ACCEPT
重啓防火牆便可
service iptables restart
這時應該能夠用 winscp進行 SFTP鏈接了 ROOT賬戶
如今開始設置FTP 默認的已經能夠用匿名登陸了
二。備份 etc/vsftpd/vsftpd.conf
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
編輯vsftpd.config文件 vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
設定不容許匿名用戶訪問。
爲了讓FLASHFXP之類的軟件更好的鏈接服務器,得讓VSFTPD支持被動模式才行,上面已經開通相應端口防火牆,在最後加入
pasv_enable=YES
pasv_max_port=30100
pasv_min_port=30000
(上面的30000--30100端口號能夠是其它的,在此舉例)
/usr/sbin/setenforce 0 馬上關閉 SELINUX
#mkdir /tmp/test //首先建立好目錄
#adduser -d /tmp/test -g ftp -s /sbin/nologin test
//-s /sbin/nologin是讓其不能登錄系統,-d 是指定用戶目錄爲/tmp/test ,即該帳戶只能登錄ftp,卻不能用作登錄系統用。-g 是指定爲FTP用戶組
#passwd test
Changing password for user beinan.//接下來會出現讓你設置新的密碼
**************************************************
【若是要刪除用戶,用下面代碼:
userdel test //userdel + 用戶 便可刪除ftp用戶】
***********************************************************
有必要的話 設置TEST目錄權限
修改/var/www目錄屬性:
$ chmod -R 777 /var/www 遞歸地給此目錄下全部文件和子目錄的讀、寫、執行權限
$ chgrp -R ftp /var/www 遞歸地把此目錄及該目錄下全部文件和子目錄的組屬性設置成ftp組
三。接着 限制用戶目錄,不得改變目錄到上級
修改/etc/vsftpd/vsftpd.conf
將這兩行
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
註釋去掉
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
新增一個文件: /etc/vsftpd/chroot_list
內容寫須要限制的用戶名:
test
從新啓動vsftpd
# service vsftpd restart
四。最後爲了防止服務器因爲斷電、重啓等現象發生,致使ftp進程在開機後未啓動,將其添加到開機啓動文件中:
(1)找到/etc/rc.local文件
(2)打開該文件,在最後一行添加:service vsftpd start
(3)保存,退出
附:vsftpd的配置文件說明:
vsftpd.ftpusers:位於/etc目錄下。它指定了哪些用戶帳戶不能訪問FTP服務器,例如root等。
vsftpd.user_list:位於/etc目錄下。該文件裏的用戶帳戶在默認狀況下也不能訪問FTP服務器,僅當vsftpd .conf配置文件裏啓用userlist_enable=NO選項時才容許訪問。
vsftpd.conf:位於/etc/vsftpd目錄下。來自定義用戶登陸控制、用戶權限控制、超時設置、服務器功能選項、服務器性能選項、服務器響應消息等FTP服務器的配置。
(1)用戶登陸控制
anonymous_enable=YES,容許匿名用戶登陸。
no_anon_password=YES,匿名用戶登陸時不須要輸入密碼。
local_enable=YES,容許本地用戶登陸。
deny_email_enable=YES,能夠建立一個文件保存某些匿名電子郵件的黑名單,以防止這些人使用Dos攻擊。
banned_email_file=/etc/vsftpd.banned_emails,當啓用deny_email_enable功能時,所需的電子郵件黑名單保存路徑(默認爲/etc/vsftpd.banned_emails)。
(2)用戶權限控制
write_enable=YES,開啓全局上傳權限。
local_umask=022,本地用戶的上傳文件的umask設爲022(系統默認是077,通常均可以改成022)。
anon_upload_enable=YES,容許匿名用戶具備上傳權限,很明顯,必須啓用write_enable=YES,纔可使用此項。同時咱們還必須創建一個容許ftp用戶能夠讀寫的目錄(前面說過,ftp是匿名用戶的映射用戶帳號)。
anon_mkdir_write_enable=YES,容許匿名用戶有建立目錄的權利。
chown_uploads=YES,啓用此項,匿名上傳文件的屬主用戶將改成別的用戶帳戶,注意,這裏建議不要指定root帳號爲匿名上傳文件的屬主用戶!
chown_username=whoever,當啓用chown_uploads=YES時,所指定的屬主用戶帳號,此處的whoever天然要用合適的用戶帳號來代替。
chroot_list_enable=YES,能夠用一個列表限定哪些本地用戶只能在本身目錄下活動,若是chroot_local_user=YES,那麼這個列表裏指定的用戶是不受限制的。
chroot_list_file=/etc/vsftpd.chroot_list,若是chroot_local_user=YES,則指定該列表(chroot_local_user)的保存路徑(默認是/etc/vsftpd.chroot_list)。
nopriv_user=ftpsecure,指定一個安全用戶帳號,讓FTP服務器用做徹底隔離和沒有特權的獨立用戶。這是vsftpd系統推薦選項。
async_abor_enable=YES,強烈建議不要啓用該選項,不然將可能致使出錯!
ascii_upload_enable=YES;ascii_download_enable=YES,默認狀況下服務器會僞裝接受ASCⅡ模式請求但其實是忽略這樣的請求,啓用上述的兩個選項可讓服務器真正實現ASCⅡ模式的傳輸。
注意:啓用ascii_download_enable選項會讓惡意遠程用戶們在ASCⅡ模式下用「SIZE/big/file」這樣的指令大量消耗FTP服務器的I/O資源。
這些ASCⅡ模式的設置選項分紅上傳和下載兩個,這樣咱們就能夠容許ASCⅡ模式的上傳(能夠防止上傳腳本等惡意文件而致使崩潰),而不會遭受拒絕服務攻擊的危險。
(3)用戶鏈接和超時選項
idle_session_timeout=600,能夠設定默認的空閒超時時間,用戶超過這段時間不動做將被服務器踢出。
data_connection_timeout=120,設定默認的數據鏈接超時時間。
(4)服務器日誌和歡迎信息
dirmessage_enable=YES,容許爲目錄配置顯示信息,顯示每一個目錄下面的message_file文件的內容。
ftpd_banner=Welcome to blah FTP service,能夠自定義FTP用戶登陸到服務器所看到的歡迎信息。
xferlog_enable=YES,啓用記錄上傳/下載活動日誌功能。
xferlog_file=/var/log/vsftpd.log,能夠自定義日誌文件的保存路徑和文件名,默認是/var/log/vsftpd.log。
anonymous_enable=YES 容許匿名登陸local_enable=YES 容許本地用戶登陸
write_enable=YES 開放本地用戶寫權限
local_umask=022 設置本地用戶生成文件的掩碼爲022
#anon_upload_enable=YES 此項設置容許匿名用戶上傳文件
#anon_mkdir_write_enable=YES 開啓匿名用戶的寫和建立目錄的權限
dirmessage_enable=YES 當切換到目錄時,顯示該目錄下的.message隱藏文件的內容
xferlog_enable=YES 激活上傳和下載日誌
connect_from_port_20=YES 啓用FTP數據端口的鏈接請求
#chown_uploads=YES 是否具備上傳權限. 用戶由chown_username參數指定。
#chown_username=whoever 指定擁有上傳文件權限的用戶。此參數與chown_uploads聯用。
#xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES 使用標準的ftpd xferlog日誌格式
#idle_session_timeout=600 此設置將在用戶會話空閒10分鐘後被中斷
#data_connection_timeout=120 將在數據鏈接空閒2分鐘後被中斷
#ascii_upload_enable=YES 啓用上傳的ASCII傳輸方式
#ascii_download_enable=YES 啓用下載的ASCII傳輸方式
#ftpd_banner=Welcome to blah FTP service 設置用戶鏈接服務器後顯示消息
#deny_email_enable=NO 此參數默認值爲NO。當值爲YES時,拒絕使用banned_email_file參數指定文件中所列出的e-mail地址用戶登陸。
#banned_email_file=/etc/vsftpd.banned_emails 指定包含拒絕的e-mail地址的文件.
#chroot_list_enable=YES 設置本地用戶登陸後不能切換到自家目錄之外的別的目錄
#chroot_list_file=/etc/vsftpd.chroot_list
#ls_recurse_enable=YES
pam_service_name=vsftpd 設置PAM認證服務的配置文件名稱,該文件存放在/etc/pam.d/
userlist_enable=YES 此項配置/etc/vsftpd.user_list中指定的用戶也不能訪問服務器,若添加userlist_deny=No,則僅僅/etc/vsftpd.user_list文件中的用戶能夠訪問,其餘用戶都不能夠訪問服務器。如過userlist_enable=NO,userlist_deny=YES,則指定使文件/etc/vsftpd.user_list中指定的用戶不能夠訪問服務器,其餘本地用戶能夠訪問服務器。
listen=YES 指明VSFTPD以獨立運行方式啓動
tcp_wrappers=YES 在VSFTPD中使用TCP_Wrappers遠程訪問控制機制,默認值爲YES
#***********************************************************************
#附 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.
#
# 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_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 whith 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
#######################################################################
來源:138vps推薦網