服務(wù)器搭建一——FTP服務(wù)器搭建

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

安裝過(guò)程

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

檢測(cè)是否啟動(dòng)

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)卡的)

  1. 重啟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
  2. 在/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)限)

db工具
生成虛擬數(shù)據(jù)庫(kù)
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è)置方法扩所。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末围详,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌助赞,老刑警劉巖买羞,帶你破解...
    沈念sama閱讀 221,273評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異雹食,居然都是意外死亡畜普,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門群叶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)吃挑,“玉大人,你說(shuō)我怎么就攤上這事街立〔俺模” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 167,709評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵赎离,是天一觀的道長(zhǎng)逛犹。 經(jīng)常有香客問(wèn)我,道長(zhǎng)梁剔,這世上最難降的妖魔是什么虽画? 我笑而不...
    開(kāi)封第一講書人閱讀 59,520評(píng)論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮荣病,結(jié)果婚禮上码撰,老公的妹妹穿的比我還像新娘。我一直安慰自己个盆,他們只是感情好脖岛,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,515評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著砾省,像睡著了一般鸡岗。 火紅的嫁衣襯著肌膚如雪混槐。 梳的紋絲不亂的頭發(fā)上编兄,一...
    開(kāi)封第一講書人閱讀 52,158評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音声登,去河邊找鬼狠鸳。 笑死,一個(gè)胖子當(dāng)著我的面吹牛悯嗓,可吹牛的內(nèi)容都是我干的件舵。 我是一名探鬼主播,決...
    沈念sama閱讀 40,755評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼脯厨,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼铅祸!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書人閱讀 39,660評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤临梗,失蹤者是張志新(化名)和其女友劉穎涡扼,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體盟庞,經(jīng)...
    沈念sama閱讀 46,203評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡吃沪,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,287評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了什猖。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片票彪。...
    茶點(diǎn)故事閱讀 40,427評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖不狮,靈堂內(nèi)的尸體忽然破棺而出降铸,到底是詐尸還是另有隱情,我是刑警寧澤摇零,帶...
    沈念sama閱讀 36,122評(píng)論 5 349
  • 正文 年R本政府宣布垮耳,位于F島的核電站,受9級(jí)特大地震影響遂黍,放射性物質(zhì)發(fā)生泄漏终佛。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,801評(píng)論 3 333
  • 文/蒙蒙 一雾家、第九天 我趴在偏房一處隱蔽的房頂上張望铃彰。 院中可真熱鬧,春花似錦芯咧、人聲如沸牙捉。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 32,272評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)邪铲。三九已至,卻和暖如春无拗,著一層夾襖步出監(jiān)牢的瞬間带到,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,393評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工英染, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留揽惹,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,808評(píng)論 3 376
  • 正文 我出身青樓四康,卻偏偏與公主長(zhǎng)得像搪搏,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子闪金,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,440評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容