1.測(cè)試環(huán)境:
Centos 6.9
虛擬主機(jī)中安裝
以Vsftpd安裝為例
2.安裝過(guò)程:
a)因?yàn)槭褂玫腃entos系統(tǒng)首先查看是否安裝和已經(jīng)是否有安裝包:
yum list |grep vsftpd
(查詢yum包中是否有安裝包瓜富,如果后面是@base就表示已經(jīng)安裝了)
b)上面是安裝的服務(wù)器端軟件,如果想使用ftp命令還需要安裝ftp軟件:yum install -y ftp
3.ftp的命令行中的命令
a)ftp后ftp>help 可以看到所有的命令
b) bye和quit 民镜! exit 相同的功能退出
c)help 和?顯示命令的幫助信息
d)append和put命令相同的功能 上傳文件 mput send
e)ascii 和binary 設(shè)置兩個(gè)文件模式
f)cd 切換遠(yuǎn)程目錄lcd切換本地目錄
g)delete 刪除遠(yuǎn)程當(dāng)前目錄的文件mdelete 刪除指定的文件
h)dir 顯示指定遠(yuǎn)程的目錄路徑下的文件和子目錄表和ls -l一樣的功能 mdir 顯示遠(yuǎn)程 mls
i)get 下載遠(yuǎn)程文件 recv
j)mkdir 在遠(yuǎn)程新建目錄
k)open 與ftp服務(wù)器連接
l)rname重新命名
m)rmdir 刪除遠(yuǎn)程目錄
n)user 指定遠(yuǎn)程計(jì)算機(jī)的用戶
o)type 設(shè)置或顯示當(dāng)前文件傳輸模式
4.圖形界面的FTP客戶端
其實(shí)使用瀏覽器輸入ftp://<ftp服務(wù)器>就可以直接訪問(wèn)ftp服務(wù)器
也可以安裝專用的ftp客戶端例如 CuteFTP
5.Vsftp 的運(yùn)行和配置
在第二步安裝完成之后寞肖,在系統(tǒng)中會(huì)存在如下文件
使用
/usr/sbin/vsftpd
啟動(dòng)進(jìn)程
使用如下的命令查看ps -aux|grep vsftpd
進(jìn)程是否啟動(dòng)
netstat -tnl|grep :21
端口是否在listen
b)配置文件的重要性/etc/vsftpd/vsftpd.config
# 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 #設(shè)定本地用戶上傳文件的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 #允許得到歡迎信息當(dāng)用戶首次進(jìn)入一個(gè)新的目錄```
`# The target log file can be vsftpd_log_file or xferlog_file.`
`# This depends on setting xferlog_std_format parameter`
`xferlog_enable=YES #允許產(chǎn)生日志`
`# Make sure PORT transfer connections originate from port 20 (ftp-data).`
`connect_from_port_20=YES #使用20號(hào)端口作為建立數(shù)據(jù)連接的源端口`
`# 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 #日志采用標(biāo)準(zhǔn)的xferlog格式`
`# 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_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=YES #vsftpd 在操作系統(tǒng)中運(yùn)行在獨(dú)立模式,并監(jiān)聽(tīng)I(yíng)Pv4端口`
`# 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 #指定PAM服務(wù)配置文件的名字备图,在/etc/pam.d目錄下`
`userlist_enable=YES #定義一個(gè)用戶列表`
`tcp_wrappers=YES #連接請(qǐng)求轉(zhuǎn)由TCP_Wrappers訪問(wèn)控制`
以上注釋部分為安裝好之后的默認(rèn)配置文件垄琐。當(dāng)采用源碼安裝時(shí)候 只有四個(gè)配置文件是有效的(anonymous_enable=YES
#允許匿名用戶,dirmessage_enable=YES
#允許得到歡迎信息當(dāng)用戶首次進(jìn)入一個(gè)新的目錄葛圃,xferlog_enable=YES
#允許產(chǎn)生日志千扔,connect_from_port_20=YES
#使用20號(hào)端口作為建立數(shù)據(jù)連接的源端口) 其他詳細(xì)配置選項(xiàng)的意思可以自行查看。
進(jìn)程重啟killall -HUP vsftpd
關(guān)閉killall vsftpd
關(guān)于匿名用戶的配置需要具體問(wèn)題具體操作库正,所有的操作都是在配置文件中完成曲楚,因此配置文件一定要熟悉。
6.Vsftpd虛擬主機(jī)的配置
Vsftpd的虛擬主機(jī)是指在一臺(tái)主機(jī)上配置多個(gè)vsftpd服務(wù)褥符,各個(gè)服務(wù)采用不同的配置文件感覺(jué)就像多個(gè)主機(jī)龙誊。是基于IP地址的,也就是說(shuō)每個(gè)vsftpd服務(wù)綁定在不同的IP地址上喷楣。如果沒(méi)有多塊網(wǎng)卡怎么辦趟大?使用邏輯網(wǎng)卡?什么是邏輯網(wǎng)卡? 下面以一個(gè)例子說(shuō)明如何配置虛擬機(jī)主機(jī)
1)新建一個(gè)邏輯網(wǎng)卡:Ifconfig eth0:1 IP地址(邏輯網(wǎng)卡) netmsak 255.255.255.0 up
2)Killall vsftpd
停止服務(wù)
3)在原有的配置文件(/etc/vsftpd/vsftpd.conf
)中增加:listen_address=IP
(主網(wǎng)卡的)
- 重啟vsftpd服務(wù):
/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf &
5)新建第二個(gè)vsftpd服務(wù)器的匿名用戶的本地帳號(hào)及個(gè)人目錄:
useradd -d /var/myftp -s /sbin/nologin myftp
chown root /var/myft
- 在/etc/vsftpd下面新建一個(gè)配置文件復(fù)制原來(lái)的文件/etc/vsftpd/vsftpd.conf 重新命名myvsftpd.conf并加入如下配置:
ftpd_banner=Welcome to my virtual ftp server ftp_username=myftp listen=yes listen_address=邏輯網(wǎng)卡的IP
7)啟動(dòng)邏輯網(wǎng)卡的vsftp
/usr/sbin/vsftpd /etc/vsftpd/myvsftpd.conf
說(shuō)明铣焊,以上七步完成就做好一個(gè)虛擬主機(jī)
7.虛擬用戶的配置
關(guān)于虛擬用戶逊朽,linux系統(tǒng)針對(duì)vsftpd中有3種用戶:a.匿名用戶:登錄可以使用任意的密碼anonymous,權(quán)限對(duì)應(yīng)于系統(tǒng)中的ftp用戶b.本地用戶就是操作系統(tǒng)中的用戶曲伊,可以用來(lái)登錄用戶名和密碼在/etc/passwd中c.虛擬用戶:用戶名和文件存放在特別的數(shù)據(jù)文件中叽讳。
使用PAM認(rèn)證模塊為例子說(shuō)明如何構(gòu)建虛擬用戶:
1)創(chuàng)建文件ftpusr.txt,里面主要是創(chuàng)建的虛擬帳號(hào),格式和內(nèi)容:
admin
admin
tony
tony
注意不要多空格和空行坟募,其中奇數(shù)行為用戶名岛蚤,偶數(shù)行為密碼。
2)生成虛擬賬戶的數(shù)據(jù)庫(kù) 需要工具DB.首先查看DB工具的是否安裝好:yum list installed|grep db4 看到如下紅色部分四個(gè)
使用db_load -T -t hash -f ./ftpusr.txt /etc/vsftpd/ftpusr.db
chmod 600 /etc/vsftpd/ftpusr.db
(修改權(quán)限)
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/ftpusr
account required /lib/security/pam_userdb.so db=/etc/vsftpd/ftpusr
這兩句意思:調(diào)用/lib/security/pam_userdb.so 模塊并根據(jù)/etc/vsftpd/ftpusr進(jìn)行認(rèn)證
4)建立所有ftp虛擬用戶帳號(hào)使用的操作系統(tǒng)帳號(hào)并設(shè)置工作目錄的權(quán)限:
useradd -d /home/ftpsite -s /sbin/nologin ftp_virt
chmod 700 /home/ftpsite
5)修改配置文件在/etc/vsftpd/vsftpd.config 增加如下內(nèi)容懈糯。重啟vsftpd服務(wù)涤妒,測(cè)試虛擬賬號(hào)是否可以正常登錄。
guest_enable=YES guest_username=ftp_virt pam_service_name=vsftpd_login
8.磁盤限額
因?yàn)樘峁┥蟼鞣?wù)時(shí)候需要赚哗,控制使用者的空間大小她紫,否則用戶上傳過(guò)大過(guò)多文件會(huì)對(duì)空間產(chǎn)生很大的影響。使用軟件quota關(guān)于具體使用屿储,本文不在討論贿讹,可以自行百度使用方法,設(shè)置方法扩所。