用Linux架設(shè)FTP服務(wù)器(下)_Ftp服務(wù)器教程
message
“message”設(shè)置當(dāng)用戶登錄或轉(zhuǎn)到一個(gè)目錄的時(shí)候會(huì)收到什么消息。可以設(shè)定多個(gè)消息。命令的格式為:
message <path> <when>
<path>表示需要顯示的文件的完整路徑名,<when>和“readme”中的<when>意思一樣。
還需要注意的是消息文件的路徑名也是相對(duì)于匿名ftp目錄的。
例如:
message /home/ftp/.welcome.msg LOGIN
compress、tar、chmod、delete、overwrite、rename
如果這些都不設(shè)置,那么就使用默認(rèn)值,也就是對(duì)所有人都是“yes”。下面例子中的設(shè)置的意思是給guest組chmod、delete、overwrite和rename文件的權(quán)力,所有人都可以使用compress和tar。
例如:
compress yes all
tar yes all
chmod yes guest
delete yes guest
overwrite yes guest
rename yes guest
log commands
因?yàn)榘踩系脑蛐枰涗浻脩羰褂玫拿恳粋(gè)命令。“l(fā)og commands”的格式是:
log commands <typelist>
<typelist>是用逗號(hào)隔開(kāi)的字串,表示哪些用戶的命令需要記錄下來(lái),字串的取值可以是:anonymous、guest或real。
例如:要記錄real和guest用戶的每一個(gè)命令,可以這么表示:
log commands real,guest
這些記錄都保存在“/var/log/message”文件中。
log transfers
因?yàn)榘踩募枰盐募膫鬏敹加涗浵聛?lái)。“l(fā)og transfers”的格式是:
log transfers <typelist> <directions>
<typelist>是用逗號(hào)隔開(kāi)的字串,表示哪些用戶的命令需要記錄下來(lái),字串的取值可以是:anonymous、guest或real。<direction>也是用逗號(hào)隔開(kāi)的字串,設(shè)置需要記錄的文件傳輸?shù)姆较颍梢赃x擇的兩個(gè)傳輸方向是“inbound”(向內(nèi))和 “outbound”(向外)。
例如,用下面表示記錄所有real和guest用戶的“inbound”和“outbound”方向的文件傳輸:
log transfers real,guest inbound,outbound
這些記錄保存在“/var/log/xferlog”文件中。
guestgroup
這個(gè)命令用來(lái)設(shè)置guest組,每一行只能有一個(gè)成員。
例如:
guestgroup ftpadmin
guestgroup webmaster
log security
用來(lái)設(shè)置記錄real、guest或anonymous用戶違反安全規(guī)則的行為。
log security <typelist>
<typelist>是用逗號(hào)隔開(kāi)的字串,字串的取值可以是:anonymous、guest或real。“real”表示真正在Ftp服務(wù)器上有帳號(hào)的用戶,“anonymous”表示匿名用戶,“guest”表示guest用戶。
例如:
log security real,guest
restricted-uid、restricted-gid、guest-root
這些用來(lái)設(shè)置是否允許real和guest用戶訪問(wèn)家目錄之外的目錄。格式為:
guest-root <root-dir>
restricted-uid <uid-range>
restricted-gid <gid-range>
例如:
guest-root /home/ftp ftpadmin webmaster
restricted-uid ftpadmin webmaster
restricted-gid adminftp webmaster
<root-dir>設(shè)置chroot環(huán)境的用戶路徑。在一行里可以有多個(gè)uid地范圍。如果為用戶設(shè)置了guest-root,那么該用戶的家目錄就在“<root-dir>/etc/passwd”文件中設(shè)定,而“/etc/passwd”文件中的設(shè)定是無(wú)效的。當(dāng)“ftpadmin”和 “webmaster”被改變了根目錄(chrooted)到“/home/ftp”目錄下,他們就被限制在各自的家目錄下而不能訪問(wèn)別人的文件。
greeting
設(shè)置用戶登錄時(shí)候的歡迎信息。格式為:
greeting full|brief|terse
“greeting full”是默認(rèn)的設(shè)置顯示主機(jī)名和ftp daemon地版本,“greeting brief”顯示主機(jī)名,“greeting terse”簡(jiǎn)單地顯示“FTP server ready”。
例如:
greeting terse
keepalive <yes|no>
設(shè)置socket的TCP SO_KEEPALIVE參數(shù)。這樣在必要的時(shí)候可以斷開(kāi)網(wǎng)絡(luò)連接。“yes”有效,“no”無(wú)效。最好設(shè)成“yes”:
Keepalive yes
配置“/etc/ftphosts”文件
“/etc/ftphosts”文件為每一個(gè)用戶建立規(guī)則,指定允許用戶從某個(gè)主機(jī)登錄ftp服務(wù)器,或者不允許用戶從某個(gè)主機(jī)登錄Ftp服務(wù)器。
創(chuàng)建“ftphosts”文件(touch /etc/ftphosts),加入下面這幾行:
# Example host access file
#
# Everything after a ‘#‘ is treated as comment,
# empty lines are ignored
allow ftpadmin 208.164.186.1 208.164.186.2 208.164.186.4
把文件的權(quán)限改為600:
[root@deep]# chmod 600 /etc/ftphosts
每一行可能是:
allow <username> <addrglob>
或
deny <username> <addrglob>
“allow”允許用戶用<username>用戶名,從<addrglob>地址訪問(wèn)Ftp服務(wù)器。<addrglob>可以包含多個(gè)地址。
“deny”禁止用戶名為<username>的用戶,從<addrglob>地址訪問(wèn)Ftp服務(wù)器。<addrglob>可以包含多個(gè)地址。
配置“/etc/ftpusers”文件
“/etc/ftpusers”文件設(shè)置哪些用戶不允許連接到Ftp服務(wù)器。
創(chuàng)建“ftpusers”文件(touch /etc/ftpusers),加入下面這幾行:
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
把文件的權(quán)限設(shè)成600:
[root@deep]# chmod 600 /etc/ftpusers
配置“/etc/ftpconversions”文件
“/etc/ftpconversions”是用來(lái)控制當(dāng)傳輸文件的時(shí)候是否進(jìn)行壓縮。
創(chuàng)建“ftpconversions”文件(touch /etc/ftpconversions),在文件中加入:
:.Z: : :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS
: : :.Z:/bin/compress -c %s:T_REG:O_COMPRESS:COMPRESS
:.gz: : :/bin/gzip -cd %s:T_REG|T_ASCII:O_UNCOMPRESS:GUNZIP
: : :.gz:/bin/gzip -9 -c %s:T_REG:O_COMPRESS:GZIP
: : :.tar:/bin/tar -c -f - %s:T_REG|T_DIR:O_TAR:TAR
: : :.tar.Z:/bin/tar -c -Z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS
: : :.tar.gz:/bin/tar -c -z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+GZIP
: : :.crc:/bin/cksum %s:T_REG::CKSUM
: : :.md5:/bin/md5sum %s:T_REG::MD5SUM
把文件的屬性改為600:
[root@deep]# chmod 600 /etc/ftpconversions
配置“/etc/pam.d/ftp”文件
配置“/etc/pam.d/ftp”文件使其支持PAM安全驗(yàn)證。
創(chuàng)建“ftp”文件(touch /etc/pam.d/ftp)并加入:
#%PAM-1.0
auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
auth required /lib/security/pam_pwdb.so shadow nullok
auth required /lib/security/pam_shells.so
account required /lib/security/pam_pwdb.so
session required /lib/security/pam_pwdb.so
配置“/etc/logrotate.d/ftpd”文件
配置“/etc/logrotate.d/ftpd”文件使得日志文件每周自動(dòng)循環(huán)更新。
創(chuàng)建“ftpd”文件(touch /etc/logrorate.d/ftpd)并加入:
/var/log/xferlog {
# ftpd doesn‘t handle SIGHUP properly
nocompress
}
配置ftp使其使用inetd超級(jí)服務(wù)器(用于實(shí)現(xiàn)tcp-wrappers)
tcp-wrappers用來(lái)啟動(dòng)和中止ftpd服務(wù)。當(dāng)inetd執(zhí)行的時(shí)候,它會(huì)從默認(rèn)為“/etc/inetd.conf”的配置文件讀入配置信息。配置文件中每一行中的項(xiàng)用TAB或空格隔開(kāi)。
編輯inetd.conf文件(vi /etc/inetd.conf),加入并驗(yàn)證是否存在下面這一行: ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a
注意:更新完“inetd.conf”文件之后要發(fā)給inetd一個(gè)SIGNUP信號(hào),運(yùn)行下面的命令:
[root@deep /root]# killall -HUP inetd
編輯“hosts.allow”文件(vi /etc/hosts.allow)加入這一行:
in.ftpd: 192.168.1.4 win.openarch.com
這表示IP地址為“192.168.1.4”并且主機(jī)名為“win.openarch.com”的計(jì)算機(jī)允許訪問(wèn)Ftp服務(wù)器。
FTP管理工具
ftpwho
ftpwho顯示當(dāng)前連接到Ftp服務(wù)器上的所有用戶。這個(gè)命令菜單輸出類似“/bin/ps”的輸出,其格式為:
<pid> <time> <tty> <connection details>
其中<pid>表示ftp daemon用來(lái)處理這次文件傳輸?shù)倪M(jìn)程號(hào),<time>表示用戶什么時(shí)候連接到Ftp服務(wù)器上,<tty>總是用問(wèn)號(hào)(?)表示因?yàn)槭峭ㄟ^(guò)ftp而不是 telnet連接,<connection details>告訴連接是來(lái)自哪里、用戶是誰(shuí)以及用戶現(xiàn)在在干什么。
下面是ftpwho輸出的一個(gè)例子:
[root@deep]# ftpwho
Service class openarch:
5443 ? S 0:00 ftpd: win.openarch.com: admin: IDLE
- 1 users ( 20 maximum)
可以看到現(xiàn)在有一個(gè)用戶登錄(最多可以有20個(gè)用戶同時(shí)登錄),這個(gè)用戶的用戶名是admin來(lái)自win.openarch.com。
ftpcount
ftpcount是ftpwho的簡(jiǎn)化版,只顯示登錄到Ftp服務(wù)器的用戶數(shù)以及最多允許多少個(gè)用戶登錄。下面是一個(gè)例子:
[root@deep]# ftpcount
Service class openarch - 1 users ( 20 maximum)
保證Ftp服務(wù)器的安全
首先確保已經(jīng)創(chuàng)建了“/etc/ftpusers”文件,這個(gè)文件用來(lái)設(shè)置不允許哪些用戶登錄Ftp服務(wù)器,其中至少要包括:root、bin、 daemon、adm、lp、sync、shutdown、halt、mail、news、uucp、operator、games、nobody以及所有Linux發(fā)行商在系統(tǒng)中提供的默認(rèn)帳號(hào)。
如果想禁止匿名ftp服務(wù),把ftp用戶從password文件中移去,再用下面的命令確定在系統(tǒng)中沒(méi)有安裝anonftp-version.i386.rpm軟件包:
[root@deep]# rpm -q anonftp.
upload命令
在默認(rèn)情況下,WU-FTPD 服務(wù)器給所有的guest用戶上載的權(quán)限。當(dāng)用戶登錄的時(shí)候,被改變根目錄(chroot)到“/home/ftp”就不能訪問(wèn)這個(gè)目錄之外的地方。但是 “/home/ftp”目錄中的一些地方還是需要保護(hù),不能讓用戶隨便訪問(wèn)。在我們配置的Ftp服務(wù)器中為“/home/ftp”目錄下的“bin”、 “etc”、“dev”和“l(fā)ib”目錄。我們不允許用戶上載文件到這些目錄。所以我們要為這些目錄設(shè)置訪問(wèn)權(quán)限,可以在 “/etc/ftpaccess”文件中設(shè)置上載權(quán)限。在我們的例子中是這樣設(shè)置的:
upload /home/ftp/* / no
upload /home/ftp/* /etc no
upload /home/ftp/* /dev no
upload /home/ftp/* /bin no (require only if you are not using the “--enable-ls” option)
upload /home/ftp/* /lib no (require only if you are not using the “--enable-ls” option)
noretrieve命令
最好禁止某些用戶從“/home/ftp”目錄下的某些子目錄中下載文件,可以用“noretrieve”命令在“/etc/ftpaccess”文件中設(shè)置。
noretrieve /home/ftp/etc
noretrieve /home/ftp/dev
noretrieve /home/ftp/bin (require only if you are not using the “--enable-ls” option)
noretrieve /home/ftp/lib (require only if you are not using the “--enable-ls” option)
“.notar”文件
無(wú)論是否允許即時(shí)的目錄打包(on-the-fly tar),都必須保證用戶不能打包(tar)禁止上載的目錄。在“/home/ftp”目錄的每個(gè)子目錄中都創(chuàng)建“.notar”文件。
[root@deep]# touch /home/ftp/.notar
[root@deep]# chmod 0 /home/ftp/.notar
[root@deep]# touch /home/ftp/etc/.notar
[root@deep]# chmod 0 /home/ftp/etc/.notar
[root@deep]# touch /home/ftp/dev/.notar
[root@deep]# chmod 0 /home/ftp/dev/.notar
[root@deep]# touch /home/ftp/bin/.notar (require only if you are not using the “--enable-ls” option)
[root@deep]# chmod 0 /home/ftp/bin/.notar (require only if you are not using the “--enable-ls” option)
[root@deep]# touch /home/ftp/lib/.notar (require only if you are not using the “--enable-ls” option)
[root@deep]# chmod 0 /home/ftp/lib/.notar (require only if you are not using the “--enable-ls” option)
這些長(zhǎng)度為0的“.notar”文件會(huì)使一些瀏覽器和ftp代理(proxy)出現(xiàn)混亂,要解決這個(gè)問(wèn)題必須把它們標(biāo)識(shí)為禁止下載。在“/etc/ftpaccess”文件中加入這一行:
noretrieve .notar
安裝到系統(tǒng)中的文件
> /etc/ftphosts
> /etc/ftpusers
> /etc/ftpaccess
> /etc/pam.d/ftp
> /etc/ftpconversions
> /etc/ftpgroups
> /etc/logrotate.d/ftpd
> /usr/bin/ftpcount
> /usr/bin/ftpwho
> /usr/man/man1/ftpcount.1
> /usr/man/man1/ftpwho.1
> /usr/man/man5/ftpaccess.5
> /usr/man/man5/ftphosts.5
> /usr/man/man5/ftpconversions.5
> /usr/man/man5/xferlog.5
> /usr/man/man8/ftpd.8
> /usr/man/man8/ftpshut.8
> /usr/man/man8/ftprestart.8
> /usr/sbin/in.ftpd
> /usr/sbin/ftpshut
> /usr/sbin/ckconfig
> /usr/sbin/ftprestart
> /usr/sbin/xferstats
> /usr/sbin/wu.ftpd
> /usr/sbin/in.wuftpd
> /var/log/xferlog
Ftp服務(wù)器教程Rss訂閱服務(wù)器教程搜索
Ftp服務(wù)器教程推薦
猜你也喜歡看這些
- Linux中“Networking Disabled”的解決方法(解決Ubuntu等系統(tǒng)無(wú)法上網(wǎng))
- Linux系統(tǒng)下如何實(shí)現(xiàn)雙網(wǎng)卡負(fù)載均衡
- Linux VPS下SSH常用命令整理
- Oracle定時(shí)器(Job)各時(shí)間段的寫(xiě)法
- Linux下查看Apache的請(qǐng)求數(shù)
- 如何在Ubunut下添加PPA 源
- linux如果忘記root密碼和grub密碼怎么辦
- Linux:如何手動(dòng)分析病毒樣本
- Linux系統(tǒng)下的C語(yǔ)言開(kāi)發(fā)都需要學(xué)些什么
- Unix和Windows在系統(tǒng)安全設(shè)計(jì)上的比較
- 相關(guān)鏈接:
- 教程說(shuō)明:
Ftp服務(wù)器教程-用Linux架設(shè)FTP服務(wù)器(下)。