vsftpd服务传输文件

文件传输协议
Vsftpd服务程序三种认证模式:
匿名开放模式、本地用户模式、虚拟用户模式
文件传输协议: 文件传输协议FTP
FTP是一种在互联网中进行文件传输的协议,基于客户端/服务器模式,默认使用20、21号端口,其中端口20(数据端口)用于数据传输,端口21(命令端口)用于接受客户端发出的相关FTP命令参数
FTP服务器是按照FTP协议在互联网上提供文件存储和访问服务的主机,FTP客户端则是向服务器发送连接请求,以建立数据传输链路的主机
FTP协议有下面两种工作模式:
主动模式:FTP服务器主动向客户端发起连接请求
被动模式:FTP服务器等待客户端发起连接请求(FTP的默认工作模式)
Vsftpd服务程序常用的参数以及作用
参数 作用
listen=[YES | NO] 是否以独立运行的方式监听服务
listen_address=IP地址 设置要监听的IP地址
listen_port=21 设置FTP服务的监听端口
download_enable=[YES | NO] 是否允许下载文件
userlist_enable=[YES |NO]
userlist_deny=[YES | NO] 设置用户列表为“允许”还是“禁止”操作
max_clients=0 最大客户端连接数,0为不限制
max_per_ip=0 同一IP地址的最大连接数,0为不限制
anonymous_enable=[ YES | NO] 是否允许匿名用户访问
anon_upload_enable=[YES | NO] 是否允许匿名用户上传文件
anon_umask=022 匿名用户上传文件的umask值
anon_root=/var/ftp 匿名用户的FTP根目录
anon_mkdir_write_enable=[YES | NO] 是否允许匿名用户创建目录
anon_other_write_enable=[YES | NO] 是否开放匿名用户的其他写入权限
anon_max_rate=0 匿名用户最大传输速率(字节/秒),0为不限制
local_enable=[YES | NO] 是否允许本地用户登录FTP
local_umask=022 本地用户上传文件的umask值
local_root=/var/ftp 本地用户的FTP根目录
chroot_local_user=[ YES | NO] 是否将用户权限禁锢在FTP目录,以确保安全
local_max_rate=0 本地用户最大传输速率(字节/秒),0为不限制
Vsftpd服务程序
Vsftpd作为更加安全的文件传输的服务程序,允许用户以三种认证模式登录到FTP服务器上。
匿名开放模式:是一种最不安全的认证模式任何人都可以无需密码验证而直接登录到FTP服务器。
本地用户模式:是通过Linux系统本地的账户密码信息进行认证的模式,相对于匿名开放模式更加安全,而且配置起来也很简单。
虚拟用户模式:是这三种模式中最安全的一种认证模式,它需要为FTP服务单独建立用户数据库文件,虚拟出用来进行口令验证的账户信息而这些账户信息在服务器系统中实际上是不存在的,仅供FTP服务程序进行认证使用
实验环节
Vsftpd非常安全的FTP守护进程是一款运行在Linux操作系统上的FTP服务程序,不仅完全开源并且免费,此外,还具有很高的安全性、传输速度、以及支持虚拟用户验证等其他的FTP服务程序不具备的特点。
1、 安装vsftpd服务程序
[root@test ~]# yum -y install vsftpd
2、 关闭防火墙或清理防火墙并保存,在默认的情况下防火墙禁止了FTP传输协议的端口号,这个两个方法选择一个即可,(关闭或者清理防火墙并保存)这两种二选一
方法一:
[root@test ~]# /etc/init.d/iptables stop
方法二:
[root@test ~]# iptables -F
[root@test ~]# service iptables save
3、 vsftpd服务程序的主配置文件,我们使用grep命令后面添加-v参数,过滤并反选出没有包含井号(#)的参数
[root@test ~]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
[root@test ~]# grep -v “#” /etc/vsftpd/vsftpd.conf.bak > /etc/vsftpd/vsftpd.conf
[root@test ~]# cat /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YE
4、 安装ftp客户端工具
[root@test ~]# yum -y install ftp

客户端下载文件
命令格式:get 文件名

客户端上传文件
命令格式:put 文件名
匿名开放模式
在vsftpd服务程序中,匿名开放模式是最不安全的一种认证模式。任何人都可以无需密码验证而直接登录到FTP服务器。这种模式一般用来访问不重要的公开文件(在生产环境中尽量不要存放重要的文件)
可以向匿名用户开放的权限参数以及作用
参数 作用
anounymous_enable=YES 允许匿名访问模式
anon_umask=022 匿名用户上传文件的umask值
anon_upload_enable=YES 允许匿名用户上传文件
anon_mkdir_write_enable=YES 允许匿名用户创建目录
anon_other_write_enable=YES 允许匿名用户修改目录名称或删除目录
1、 vsftpd主配置文件修改
[root@test ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
anon_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
listen_ipv6=YES //在虚拟机环境中不需要改变此处忽略
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
2、 重启vsftpd服务程序将服务程序添加到开机启动项中,确保下次服务器在重启后依然能够正常提供服务
[root@test ~]# /etc/init.d/vsftpd restart
关闭 vsftpd: [失败]
为 vsftpd 启动 vsftpd: [确定]
[root@test ~]# chkconfig vsftpd on
3、 使用客户端访问vsftpd,在客户端上安装ftp服务程序
在vsftpd服务程序的匿名开放认证模式下,其账户统一为anonymous,密码为空。
[root@python ~]# yum -y install ftp
[root@python ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): anonymous //默认用户名
331 Please specify the password.
Password: //此处回车
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
4、 修改FTP默认访问的目录权限,对/var/ftp目录
[root@test ~]# ls -ld /var/ftp/pub/
drwxr-xr-x 2 root root 4096 3月 1 2013 /var/ftp/pub/
[root@test ~]# chown -Rf ftp /var/ftp/pub
[root@test ~]# ls -ld /var/ftp/pub/
drwxr-xr-x 2 ftp root 4096 3月 1 2013 /var/ftp/pub/
5、 使用客户端访问vsftpd,并且创建一个目录试试,是否可以创建
[root@python ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): anonymous //匿名用户默认
331 Please specify the password.
Password: //此处回车
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub //切换目录
250 Directory successfully changed.
ftp> mkdir duzhengbin //创建一个duzhengbin目录成功了的
257 “/pub/duzhengbin” created
如果此时还是不能创建目录,就得查看selinux域策略了
[root@python ~]# getsebool -a | grep ftp
ftpd_full_access —> off
[root@python ~]# setsebool -P ftpd_full_access=on
或者直接关闭selinux
[root@python ~]# setenforce 0 //这个0是数字零
本地用户模式
本地用户模式比匿名用户模式更加安全,而且配置起来也很简单,如果之前使用的是匿名开放模式,现在就可以将它关闭了,然后开启本地用户模式。
本地用户模式使用的权限参数以及作用
参数 作用
anonymous_enable=NO 禁止匿名访问模式
local_enable=YES 允许本地用户模式
write_enable=YES 设置可写权限
local_umask=022 本地用户模式创建文件的umask值
userlist_enable=YES 启用“禁止用户名单”,名单文件为ftpusers和user_list
userlist_deny=YES 开启用户作用名单文件功能
1、 对vsftpd配置文件进行修改
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
2、 重新启动vsftpd服务
[root@test ~]# /etc/init.d/vsftpd restart
3、 现在就可以使用本地用户登录FTP了,(这里我们使用rot做测试一下看一下root能不能成成功登陆,
[root@test ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): root
530 Permission denied. // 530登录不正确。
Login failed. //登录失败
ftp>
这里我们输入root管理员的密码之前,就已经被系统拒绝访问了,在vsftpd服务程序所在的目录中默认存放着两个名为“用户名单”的文件(ftpusers和user_list)。在这两个文件中有写的某个用户的名字,就不再允许这位用户登录到FTP服务器上。
[root@test ftp]# cat /etc/vsftpd/ftpusers

Users that are not allowed to login via ftp

root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

[root@test ftp]# cat /etc/vsftpd/user_list

vsftpd userlist

If userlist_deny=NO, only allow users in this file

If userlist_deny=YES (default), never allow users in this file, and

do not even prompt for a password.

Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers

for users that are denied.

root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
[root@test ftp]#
4、 创建两个本地用户xiaowu、xiaoliu
[root@test ~]# useradd -s /sbin/nologin xiaowu //创建用户xiaowu
[root@test ~]# passwd xiaowu //设置密码,输入两次

[root@test ~]# useradd -s /sbin/nologin xiaoliu //创建用户xiaoliu
[root@test ~]# passwd xiaoliu //设置密码,输入两次
5、 修改ftpusers文件

Users that are not allowed to login via ftp

root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody //在行尾添加
xiaoliu
6、 重新启动服务
[root@test ~]# /etc/init.d/vsftpd restart
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定]
7、 测试,xiaoliu添加到了黑名单中,不让其登录,xiaowu可以正常登录
[root@test ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): xiaoliu //用户xiaoliu
331 Please specify the password.
Password:
530 Login incorrect. 不允许登陆
Login failed.
ftp> bye
221 Goodbye.

[root@test ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): xiaowu //用户xiaowu
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX. //登录成功
Using binary mode to transfer files.
ftp> ls //查看
227 Entering Passive Mode (10,10,10,101,157,179).
150 Here comes the directory listing.
drwx------ 5 500 500 4096 Dec 13 08:49 kuteng
drwx------ 2 0 0 16384 Dec 13 06:41 lost+found
drwx------ 4 502 502 4096 Dec 13 08:57 xiaoliu
drwx------ 4 501 501 4096 Dec 13 08:57 xiaowu
226 Directory send OK.
虚拟用户模式
1、 创建ftp用户数据库文件
[root@test xiaoliu]# cd /etc/vsftpd/
[root@test vsftpd]# vim vuser //创建ftp用户数据库文件,奇数行为用户名,偶数为密码
xiaodu
asdzxc
dandan
asdzxc
2、 对vuser文件进行加密转换为数据库文件
[root@test vsftpd]# db_load -T -t hash -f vuser vuser.db //转换为数据库文件
[root@test vsftpd]# chmod 600 vuser.db //修改权限不让其他的用户查看
[root@test vsftpd]# rm -f vuser
3、 创建vsftpd服务程序用户存储文件的根目录以及虚拟用户映射的系统本地用户
[root@test vsftpd]# useradd -d /opt/vuser -s /sbin/nologin vuser
[root@test ~]# ls -ld /opt/vuser/
drwx------ 4 vuser vuser 4096 12月 13 17:43 /opt/vuser/
[root@test ~]# chmod -Rf 755 /opt/vuser/
4、 建立用户支持虚拟用户的PAM认证模块文件
[root@test vsftpd]# vim /etc/pam.d/vsftpd.vu
auth required pam_userdb.so db=/etc/vsftpd/vuser
account required pam_userdb.so db=/etc/vsftpd/vuser
5、 修改vsftpd服务程序的主配置文件
[root@test vsftpd]# vim /etc/vsftpd/vsftpd.conf

anonymous_enable=NO
local_enable=YES
guest_enable=YES
guest_username=vuser
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES

pam_service_name=vsftpd.vu
userlist_enable=YES
tcp_wrappers=YES
6、 重启服务
[root@test vsftpd]# /etc/init.d/vsftpd restart
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定]
7、 测试
客户端使用虚拟账户xiaodu进行登陆,可以正常登录
[root@test ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): xiaodu
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (10,10,10,101,192,180).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Dec 13 10:03 kk
-rw-r–r-- 1 0 0 0 Dec 13 10:03 kuteng
226 Directory send OK.
ftp> ls
227 Entering Passive Mode (10,10,10,101,97,108).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Dec 13 10:03 kk
-rw-r–r-- 1 0 0 0 Dec 13 10:03 kuteng
226 Directory send OK.

[root@test ~]# ftp 10.10.10.101
Connected to 10.10.10.101 (10.10.10.101).
220 (vsFTPd 2.2.2)
Name (10.10.10.101:root): dandan
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (10,10,10,101,222,34).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Dec 13 10:03 kk
-rw-r–r-- 1 0 0 0 Dec 13 10:03 kuteng
226 Directory send OK.
ftp> ls
227 Entering Passive Mode (10,10,10,101,243,118).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Dec 13 10:03 kk
-rw-r–r-- 1 0 0 0 Dec 13 10:03 kuteng
226 Directory send OK.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彩虹龙

您的鼓励将是我创作最大的努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值