Linux基础知识 vsftpd,samba服务器侧写配置详解

本节中要介绍下配置vsftp匿名上传和samba文件共享,这是文件系统上的两个经典的实验,有必要整理整理

1:匿名FTP允许上传,在/var/ftp目录下新建一个incoming目录,允许匿名用户上传数据

[root@server ~]# rpm -qa |grep vsftpd  //确认安装了vsftpd,若未安装,则使用yum来安装
vsftpd-2.0.5-16.el5
[root@server ~]# cd /var/ftp/
[root@server ftp]# ls -Z            //查看pub的selinux的语境
drwxr-xr-x root root system_u:object_r:public_content_t pub

[root@server ftp]# chgrp ftp incoming/  //设定incoming目录的属主,权限
[root@server ftp]# chmod 730 incoming/
[root@server ftp]# chcon -t public_content_rw_t incoming  //允许匿名用户写入incoming目录的selinx语境设定
[root@server ftp]# setsebool -P allow_ftpd_anon_write on    //调整selinux关于匿名用户上传的布尔值

[root@server ~]# grep -v '^#' /etc/vsftpd/vsftpd.conf
anonymous_enable=YES    //允许匿名用户登录
local_enable=YES        //允许本地用户登录
write_enable=YES        //允许本地用户写入自己的家目录
local_umask=022          //本地文件反向掩码
anon_upload_enable=YES  //允许匿名用户上传,本实验重点
dirmessage_enable=YES    //启用登录欢迎消息
xferlog_enable=YES      //记录日志
connect_from_port_20=YES //控制端口为tcp 20
chown_uploads=YES        //改变匿名用户上传的文件属主,本实验重点
chown_username=daemon    //将匿名用户上传的文件属主改为daemon,本实验重点
anon_umask=077            //匿名用户上传文件反向掩码
xferlog_std_format=YES    //以标准格式记录日志
listen=YES                //监听端口
connect_from_port_20=YES //启用TCP 20端口做为控制端口

[root@server ~]# service vsftpd start //启动服务,并保证下次开机自动启动
Starting vsftpd for vsftpd: [ OK ]
[root@server ~]# chkconfig vsftpd on

客户端测试:
C:\>ftp 192.168.100.20
连接到 192.168.100.20。
220 (vsFTPd 2.0.5)
用户(192.168.100.20:(none)): ftp
331 Please specify the password.
密码:
230 Login successful.
ftp> pwd
257 "/"    //默认匿名用户执行chroot,非匿名用户则不执行chroot
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
incoming
pub
226 Directory send OK.
ftp: 收到 15 字节,用时 0.00秒 15000.00千字节/秒。
ftp> cd incoming
250 Directory successfully changed.

ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).
ftp> put c:\1.txt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 5 字节,用时 0.23秒 0.02千字节/秒。

ftp> ls
200 PORT command successful. Consider using PASV. //由于目录设定成730,故没有匿名用户没有ls权限
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).

[root@server incoming]# ll  //服务器端验证,权限为600,属主为daemon,ftp主机级的访问控制可以接着tcpwrap和iptables实现
total 8
-rw------- 1 daemon ftp 5 Mar 25 02:49 1.txt

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/27275.html