📄 1477.html
字号:
<br>
PAM应用也就是在开启了PAM的系统上应用“虚拟用户”功能。下面一个样例演示怎样利用“虚拟用户”来设置vsftpd的PAM。虚拟用户是指不像系统上的真实用户一样客观存在的用户。虚拟用户因此而比真实用户更安全,因为一个像这样有威胁系统安全的账户却仅能使用FTP服务。虚拟用户常用来服务那些不想开放给不被信任用户的内容,一般不影响正常的普通用户。<br>
<br>
1.创建虚拟用户数据库<br>
<br>
使用pam_userdb来鉴别虚拟用户。这需要一个“db”格式的用户名/密码文件。要创建一个“db”格式文件,首先要创建一个在交替行上写有用户名和密码的无格式文本文件,代码如下:<br>
<br>
$ vi logins.txt<br>
<br>
<br>
<br>
编辑文件内容如下:<br>
<br>
tom<br>
foo<br>
fred<br>
bar<br>
<br>
<br>
<br>
上面的“tom”对应着密码“foo”,“fred”对应着密码“bar”。同时用root身份登陆,创建实际的数据库文件,代码如下:<br>
<br>
$ db_load -T -t hash -f logins.txt /etc/vsftpd_login.db<br>
<br>
<br>
<br>
# 要求已安装了Berkeley db 程序<br>
<br>
这样即可创建“/etc/vsftpd_login.db”。如果想改变访问许可权限,可用如下命令:<br>
<br>
$ chmod 600 /etc/vsftpd_login.db<br>
<br>
<br>
<br>
此外,如果想了解更多有关如何维护登陆数据库的知识,可寻找在“Berkeley DB”上的文档资料,网址为http://www.sleepycat.com/docs/utility/index.html。<br>
<br>
2.建一个使用新数据库的PAM文件<br>
<br>
创建编辑文件vsftpd.pam,包含以下两行:<br>
<br>
auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login<br>
accound required /lib/security/pam_userdb.so db=/etc/vsftpd_login<br>
<br>
<br>
<br>
告诉PAM使用新数据库来鉴别用户。把该PAM文件保存到PAM目录(通常为“/etc/pam.d/cp vsftpd.pam /etc/pam.d/ftp”)。<br>
<br>
3.为虚拟用户设置文件位置<br>
<br>
接下来使用以下命令为为虚拟用户设置文件位置:<br>
<br>
$ useradd -d /home/ftpsite virtual<br>
$ ls -ld /home/ftpsite<br>
<br>
<br>
<br>
将显示如下:<br>
<br>
drwx------3 virtual virtual 4096 Jul 30 00:39 /home/ftpsite<br>
<br>
<br>
<br>
已经创建一个叫做“virtual”的用户,并且有一个主目录“/home/ftpsite”。增加一些内容到这个下载区域,代码如下:<br>
<br>
$ cp /etc/hosts /home/ftpsite<br>
$ chown virtual.virtual /home/ftpsite/hosts<br>
<br>
<br>
<br>
4.定制vsftpd.conf配置文件<br>
<br>
重新定制vsftpd.conf文件:<br>
<br>
anonymous_enable=NO<br>
local_enable=YES<br>
# 由于安全因素应关闭匿名FTP,并开启非匿名FTP(虚拟用户需使用)。<br>
write_enable=NO<br>
anon_upload_enable=NO<br>
anon_mkdir_write_enable=NO<br>
anon_other_write_enable=NO<br>
# 出于安全目的写下这些确保命令,不许写命令执行<br>
chroot_local_user=YES<br>
# 限制虚拟用户到我们上面设置的虚拟FTP区域 /home/ftpsite。<br>
guest_enable=YES<br>
guest_username=virtual<br>
# guest_enable很重要,能激活虚拟用户。guest_username表示所有<br>
的虚拟用户都被映射到上面设置的真实用户“virtual”。这也将确定在文件系统上<br>
虚拟用户的最终归宿,用户“virtual”的主目录“/home/ftpsite”。<br>
listen=YES<br>
listen_port=10021<br>
# 这置vsftpd在“standalone”模式,不从inetd运行。这意味着仅需执行vsftpd<br>
运行命令一次,它就开始运行起来。这也使得vsftpd监听在10021的非标准端口上<br>
的FTP需求(FTP通常使用端口21)。<br>
pasv_min_port=30000<br>
pasv_max_port=30999<br>
# 这些命令在被动FTP接收端放置一个端口序列。对配置防火墙很有用。<br>
<br>
<br>
<br>
5.开始运行vsftpd<br>
<br>
进入vsftpd源代码所在的目录,并执行“./vsftpd”,如果光标一直停在那里说明无误;否则将会看到一些错误信息。<br>
<br>
6.测试<br>
<br>
装载另一个Shell会话进程(或者把程序切换到后台运行,按CTRL+Z然后敲“bg”)。以下是一个FTP会话样例:<br>
<br>
ftp localhost 10021<br>
Connected to localhost (127.0.0.1).<br>
220 ready, dude (vsFTPd 1.1.3: beat me, break me)<br>
Name (localhost:chris): tom<br>
331 Please specify the password.<br>
Password:<br>
230 Login successful. Have fun.<br>
Remote system type is UNIX.<br>
Using binary mode to transfer files.<br>
ftp> pwd<br>
257 "/"<br>
ftp> ls<br>
227 Entering Passive Mode (127,0,0,1,117,135)<br>
150 Here comes the directory listing.<br>
226 Transfer done (but failed to open directory).<br>
ftp> size hosts<br>
213 147<br>
ftp><br>
<br>
<br>
<br>
这里给出的密码是“foo”。不要因为出现“failed to open directory”而害怕,那是因为目录“/home/ftpsite”不全部可读。可以看到,通过size命令已经访问到复制进虚拟FTP区域的“hosts”文件。<br>
<br>
功能扩充<br>
<br>
虽然第一个vsftpd已经可以运行,但下面的内容可以扩充“VIRTUAL_USERS”,使设置变得稍微复杂一些。假定需要两类虚拟用户,一类仅仅能浏览和下载内容,另一种除能下载存在的内容之外还能上传新内容。可使用vsftpd强大的单用户使用配置能力(版本1.1.0以上)来完成这个设置。我们在早先的虚拟用户样例中创建了tom和fred两个用户,并设置fred拥有写权限,可访问上传的新文件;tom仅能下载。<br>
<br>
1.激活单用户配置能力<br>
<br>
要激活vsftpd的这个强大功能,增加下面的内容到“/etc/vsftpd.conf”:<br>
<br>
user_config_dir=/etc/vsftpd_user_conf<br>
<br>
<br>
<br>
并用“mkdir /etc/vsftpd_user_conf”创建目录。<br>
<br>
2.给tom读取所有文件/目录的能力<br>
<br>
在上个样例的末尾, 我们注意到虚拟用户仅能看全可读文件和目录。可以使“/home/ftpsite”目录全可读,并且上传有全可读许可的文件。但是做到这点的另一种方法是给tom下载非全可读文件的能力。<br>
<br>
对于用户tom,强行提供一个配置设置给“anon_world_readable_only”,代码如下:<br>
<br>
echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/tom<br>
<br>
<br>
<br>
然后检测一下,用tom登录,键入“ls”将返回目录清单。而用fred登录则应不显示。<br>
<br>
可以重启vsftpd使刚才对“/etc/vsftpd.conf”文件的更改有效(高级用户可发送SIGHUP给vsftpd监听进程)。<br>
<br>
3.给fred读取所有文件/目录和创建新文件/目录的权限,但是不具有干扰已经存在文件的能力,代码如下:<br>
<br>
echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/fred<br>
echo "write_enable=YES" >> /etc/vsftpd_user_conf/fred<br>
echo "anon_upload_enable=YES" >> /etc/vsftpd_user_conf/fred<br>
<br>
<br>
<br>
最后检测一下,用tom登陆应该不能上传;而用fred登录能上传。并试着分别用tom和fred删除一个文件,应不能删除。<br>
<br>
总结<br>
<br>
以上实例均在Red Hat 8.0系统上试验通过,如遇到问题请仔细检查每个细节的正确性。实例中的内容可以根据具体环境进行增减、修改。相信稍加变通便可以打造出一个满意的、安全的FTP服务器。<br>
[返回列表]
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -