Linux之vsftpd服务配置

本文详细介绍了如何在Linux上配置vsftpd服务,包括ftp的主动和被动模式、安装与连接过程、服务配置参数如匿名用户和本地用户的权限设定,以及如何进行用户访问控制,如黑白名单和chroot限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ftp 是为系统提供了通过网络与远程服务器进行传输的简单方法,只要在服务端配置好,在客户端就可以下载相应的文件。
服务端:安装 vsftpd
客户端:安装 lftp

ftp的两种模式

主动模式:客户端随机开启端口N(>1024),向服务器的命令端口21发送连接请求,连接后,客户端开放端口N+1进行监听,并向服务器发送port N+1命令,服务器收到命令后通过数据端口20与客户端的N+1端口进行数据传输。
被动模式:客户端随机开启端口N,向服务器的命令端口21发送连接请求,连接后,客户端向服务器发送PASV命令,告诉服务器自己处于被动模式,服务器收到后,会选择端口P(>1024)并发送port P命令给客户端,客户端收到命令后通过端口N+1与服务器的端口P进行数据传输。

部署ftp服务

实验用虚拟机做测试
实验:本实验是在真机上面连接虚拟机做的实验,真机是客户端

服务端:
[root@localhost ~]# vim /etc/sysconfig/selinux 关闭selinux,如下为文件内容
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled  修改内容
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]# reboot  #重启
Connection to 172.25.254.196 closed by remote host.
Connection to 172.25.254.196 closed.
[kiosk@foundation69 Desktop]$ ssh root@172.25.254.196 -X  #连接虚拟机
root@172.25.254.196's password: 
Last login: Mon May  7 07:26:37 2018 from 172.25.254.69
[root@localhost ~]# yum install vsftpd -y   #下载vsftpd
[root@localhost ~]# systemctl start vsftpd    #打开vsftpd
[root@localhost ~]# systemctl enable vsftpd
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service'
[root@localhost ~]# netstat -antlupe | grep vsftpd
tcp6       0      0 :::21                   :::*                    LISTEN      0          39283      1867/vsftpd         
[root@localhost ~]# firewall-cmd --list-all  #查看防火墙规则
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
#添加ftp到防火墙允许的服务里面:
[root@localhost ~]# firewall-cmd --permanent --add-service=ftp 
success
[root@localhost ~]# firewall-cmd --reload    #更新防火墙规则
success
[root@localhost ~]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ftp ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@localhost ~]# touch /var/ftp/hellohello  新建文件测试
[root@localhost ~]# ls /var/ftp/  查看目录ftp中的内容
hellohello  pub
客户端:
[root@foundation69 ~]# lftp 172.25.254.196
lftp 172.25.254.196:~> ls
-rw-r--r--    1 0        0               0 May 07 12:30 hellohello
drwxr-xr-x    2 0        0               6 Mar 07  2014 pub
lftp 172.25.254.196:/> quit
文件信息、报错id

默认发布目录: /var/ftp
协议接口: 21/tcp
服务配置文件: /etc/vsftpd/vsftpd.conf
报错id的解析:
500 #文件系统权限过大
530 #用户认证失败
550 #服务本身功能未开放
553 #本地文件系统权限过小

ftpd 服务的配置参数

man 5 vsftpd.conf 可以查看具体参数
匿名用户:
匿名用户登录 anonymous_enable=YES|NO
匿名用户加目录修改 anon_root=/direcotry
匿名用户上传 anon_upload_enable=YES
匿名用户建立目录 anon_mkdir_write_enable=YES|NO
匿名用户下载 anon_world_readable_only=NO
匿名用户删除 anon_other_write_enable=YES
匿名用户最大传输速率,单位字节 anon_max_rate=需要设置的字节大小
匿名用户上传文件权限 anon_umask
本地用户:
本地用户登陆 local_enable=YES|NO
是否对登陆用户可写 write_enable=YES|NO
本地用户上传文件权限 local_umask
限制本地用户浏览目录:
所有用户被锁定到自己的家目录 chroot_local_user=YES
用户黑名单建立(修改黑白名单不需要重启)
chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
用户白名单建立
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
限制本地用户登陆
/etc/vsftpd/ftpusers #永久黑名单,优先级高于一切
/etc/vsftpd/user_list #临时黑名单
用户白名单设定
userlist_deny=NO # /etc/vsftpd/user_list 文件改变成白名单,与黑名单 ftpusers 中相同的用户,按照黑名单对待

1、匿名用户登陆
anonymous_enable=YES|NO #匿名用户是否可以登陆

当服务端设置为YES时,在客户端测试
[root@foundation69 ~]# lftp 172.25.254.196
lftp 172.25.254.196:~> ls
-rw-r--r--    1
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值