1.測試環境:
Centos 6.9
虛擬主機中安裝
以Vsftpd安裝為例
2.安裝過程:
a)因為使用的Centos系統首先查看是否安裝和已經是否有安裝包:
yum list |grep vsftpd
(查詢yum包中是否有安裝包,如果后面是@base就表示已經安裝了)
b)上面是安裝的服務器端軟件,如果想使用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 設置兩個文件模式
f)cd 切換遠程目錄lcd切換本地目錄
g)delete 刪除遠程當前目錄的文件mdelete 刪除指定的文件
h)dir 顯示指定遠程的目錄路徑下的文件和子目錄表和ls -l一樣的功能 mdir 顯示遠程 mls
i)get 下載遠程文件 recv
j)mkdir 在遠程新建目錄
k)open 與ftp服務器連接
l)rname重新命名
m)rmdir 刪除遠程目錄
n)user 指定遠程計算機的用戶
o)type 設置或顯示當前文件傳輸模式
4.圖形界面的FTP客戶端
其實使用瀏覽器輸入ftp://<ftp服務器>就可以直接訪問ftp服務器
也可以安裝專用的ftp客戶端例如 CuteFTP
5.Vsftp 的運行和配置
在第二步安裝完成之后,在系統中會存在如下文件
使用
/usr/sbin/vsftpd
啟動進程
使用如下的命令查看ps -aux|grep vsftpd
進程是否啟動
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 #設定本地用戶上傳文件的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 #使用20號端口作為建立數據連接的源端口`
`# 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 #日志采用標準的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 在操作系統中運行在獨立模式,并監聽IPv4端口`
`# 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服務配置文件的名字,在/etc/pam.d目錄下`
`userlist_enable=YES #定義一個用戶列表`
`tcp_wrappers=YES #連接請求轉由TCP_Wrappers訪問控制`
以上注釋部分為安裝好之后的默認配置文件。當采用源碼安裝時候 只有四個配置文件是有效的(anonymous_enable=YES
#允許匿名用戶,dirmessage_enable=YES
#允許得到歡迎信息當用戶首次進入一個新的目錄,xferlog_enable=YES
#允許產生日志,connect_from_port_20=YES
#使用20號端口作為建立數據連接的源端口) 其他詳細配置選項的意思可以自行查看。
進程重啟killall -HUP vsftpd
關閉killall vsftpd
關于匿名用戶的配置需要具體問題具體操作,所有的操作都是在配置文件中完成,因此配置文件一定要熟悉。
6.Vsftpd虛擬主機的配置
Vsftpd的虛擬主機是指在一臺主機上配置多個vsftpd服務,各個服務采用不同的配置文件感覺就像多個主機。是基于IP地址的,也就是說每個vsftpd服務綁定在不同的IP地址上。如果沒有多塊網卡怎么辦?使用邏輯網卡?什么是邏輯網卡? 下面以一個例子說明如何配置虛擬機主機
1)新建一個邏輯網卡:Ifconfig eth0:1 IP地址(邏輯網卡) netmsak 255.255.255.0 up
2)Killall vsftpd
停止服務
3)在原有的配置文件(/etc/vsftpd/vsftpd.conf
)中增加:listen_address=IP
(主網卡的)
- 重啟vsftpd服務:
/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf &
5)新建第二個vsftpd服務器的匿名用戶的本地帳號及個人目錄:
useradd -d /var/myftp -s /sbin/nologin myftp
chown root /var/myft
- 在/etc/vsftpd下面新建一個配置文件復制原來的文件/etc/vsftpd/vsftpd.conf 重新命名myvsftpd.conf并加入如下配置:
ftpd_banner=Welcome to my virtual ftp server ftp_username=myftp listen=yes listen_address=邏輯網卡的IP
7)啟動邏輯網卡的vsftp
/usr/sbin/vsftpd /etc/vsftpd/myvsftpd.conf
說明,以上七步完成就做好一個虛擬主機
7.虛擬用戶的配置
關于虛擬用戶,linux系統針對vsftpd中有3種用戶:a.匿名用戶:登錄可以使用任意的密碼anonymous,權限對應于系統中的ftp用戶b.本地用戶就是操作系統中的用戶,可以用來登錄用戶名和密碼在/etc/passwd中c.虛擬用戶:用戶名和文件存放在特別的數據文件中。
使用PAM認證模塊為例子說明如何構建虛擬用戶:
1)創建文件ftpusr.txt,里面主要是創建的虛擬帳號,格式和內容:
admin
admin
tony
tony
注意不要多空格和空行,其中奇數行為用戶名,偶數行為密碼。
2)生成虛擬賬戶的數據庫 需要工具DB.首先查看DB工具的是否安裝好:yum list installed|grep db4 看到如下紅色部分四個
使用db_load -T -t hash -f ./ftpusr.txt /etc/vsftpd/ftpusr.db
chmod 600 /etc/vsftpd/ftpusr.db
(修改權限)
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/ftpusr
account required /lib/security/pam_userdb.so db=/etc/vsftpd/ftpusr
這兩句意思:調用/lib/security/pam_userdb.so 模塊并根據/etc/vsftpd/ftpusr進行認證
4)建立所有ftp虛擬用戶帳號使用的操作系統帳號并設置工作目錄的權限:
useradd -d /home/ftpsite -s /sbin/nologin ftp_virt
chmod 700 /home/ftpsite
5)修改配置文件在/etc/vsftpd/vsftpd.config 增加如下內容。重啟vsftpd服務,測試虛擬賬號是否可以正常登錄。
guest_enable=YES guest_username=ftp_virt pam_service_name=vsftpd_login
8.磁盤限額
因為提供上傳服務時候需要,控制使用者的空間大小,否則用戶上傳過大過多文件會對空間產生很大的影響。使用軟件quota關于具體使用,本文不在討論,可以自行百度使用方法,設置方法。