vfstpd

主配置文件/etc/vsftpd/vsftpd.conf

# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO     ------控制匿名用户访问权限,YES表示允许匿名访问FTP服务器。
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES    ---控制FTP用户是否可以访问FTP服务器,YES表示允许FTP用户访问FTP服务,
同时当selinux处于enforcing状态时,需要调整ftp_home_dir的bool值。
(但是从RHEL7上安装vsftpd3.0版本后,就是没有ftp_home_dir这个bool值了,
所以就不需要修改此bool值)
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES     ----控制FTP用户对FTP服务器的可写权限,YES表示可写。
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022      ----FTP用户创建目录或文件时的umask值


# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES       ----控制匿名用户上传文件的权限,YES表示允许匿名用户上传文件。
当selinux处于enforcing状态时,需要调整ftpd_anon_write和ftpd_full_access的bool值。

#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES   ---控制匿名用户创建目录的权限,YES表示允许匿名用户创建目录

#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES          ---显示说明性文件
#
# Activate logging of uploads/downloads.
xferlog_enable=YES           ---控制文件在传输过程中是否被日志记录,YES表示记录
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES        ----强制使用20端口进行数据传输


# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES           --设置为YES时,默认匿名用户上传文件的所有者为FTP
#chown_username=whoever   ---whoever修改为ftp用户,匿名用户上传文件的所有者将变成该FTP用户。


#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog          ---设置FTP服务日志文件位置
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES        ---设置标准的FTP Xferlog模式

#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600    ---控制连接超过600秒空闲时,自动断开连接
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120    ---控制数据连接建立后120秒内无交互时,自动断开连接。

# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure    ---非特权状态下使用ftpsecure用户


You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.   ---成功连接FTP服务器时的提示语

#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES            ---禁止下载文件到指定的邮箱地址中
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails     ---设置电子邮箱地址


# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES        ---控制FTP用户能否离开自己的FTP主目录,
YES表示禁止FTP用户离开自己的FTP主目录。

#chroot_list_enable=YES        ---控制列表中的FTP用户能否离开自己的FTP主目录,
YES表示禁止列表中的FTP用户离开自己的FTP主目录。默认是允许
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list    ---FTP用户列表文件,每一行一个用户名

#ls_recurse_enable=YES   ---控制FTP用户是否能使用类似 ls -R命令,
默认是禁止的,YES表示允许使用


# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO            ---控制是否侦听ipv4套接字,NO表示不侦听ipv4套接字,
不能同时设置侦听ipv4和ipv6套接字

listen_ipv6=YES   --控制是否侦听ipv6套接字,YES表示侦听ipv6套接字,
默认情况下侦听ipv6的任意地址,此时能够接受来自客户端ipv6的连接和ipv4的连接

pam_service_name=vsftpd    ---设置PAM认证文件的名称
userlist_enable=YES         ---控制是否启动/etc/vsftpd/user_list文件,YES表示启动
tcp_wrappers=YES    ---控制是否启用/etc/hosts.allow和/etc/hosts.deny配置文件
管理网络主机对FTP服务的访问,YES表示启用。

示例一、匿名用户

1、设置允许匿名用户访问FTP服务器
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:~> ls
drwxrwxr-x    2 0        0               6 Oct 30  2023 pub

2、设置允许匿名用户访问FTP服务器时能够在/var/ftp/pub目录下进行文件上传
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
write_enable=YES
anon_upload_enable=YES
[root@server vsftpd]# setfacl -m u:ftp:rwx /var/ftp/pub/ //赋予写入权限
验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:/> cd pub/
lftp 192.168.35.142:/pub> put file2
lftp 192.168.35.142:/pub> ls
-rw-------    1 14       50              0 Jul 23 00:33 file2

3、设置允许匿名用户访问FTP服务器时能够在/var/ftp/pub目录下创建目录
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
write_enable=YES
anon_mkdir_write_enable=YES
验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:/> cd pub/
lftp 192.168.35.142:/pub> mkdir lsy
mkdir ok, `lsy' created
lftp 192.168.35.142:/pub> ls
-rw-------    1 14       50              0 Jul 23 00:33 file2
drwx------    2 14       50              6 Jul 23 00:36 lsy

4、设置允许匿名用户访问FTP服务器时能够对/var/ftp/pub目录中的文件或
目录进行重命名或删除操作
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
write_enable=YES
anon_other_write_enable=YES
验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:/pub> rm -rf lsy
rm ok, `lsy' removed
lftp 192.168.35.142:/pub> mv file2 file22
rename successful
lftp 192.168.35.142:/pub> ls
-rw-------    1 14       50              0 Jul 23 00:33 file22

示例二、FTP用户

[root@server vsftpd]# useradd user1 //添加三个用户,使用循环添加密码
[root@server vsftpd]# useradd user2
[root@server vsftpd]# useradd user3
[root@server vsftpd]# for i in user{1..3}
> do echo redhat | passwd --stdin $i
> done
Changing password for user user1.
passwd: all authentication tokens updated successfully.
Changing password for user user2.
passwd: all authentication tokens updated successfully.
Changing password for user user3.
passwd: all authentication tokens updated successfully.

1、设置允许FTP用户访问FTP服务器
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
local_enable=YES
write_enable=YES
验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:~> user user1
Password: 
lftp user1192.168.35.142:~> user user2
Password: 
lftp user2@192.168.35.142:~> user user3
Password: 

2、设置FTP用户访问FTP服务器时,将所有FTP用户访问的目录限制在自己的主目录中,
不允许FTP用户访问其他目录
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
chroot_local_user=YES


验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:~> cd pub/
lftp 192.168.35.142:/pub> user user1
Password: 
lftp user1@192.168.35.142:~> ls
ls: Login failed: 530 Login incorrect
// 此时查看报错,因为vsftpd系统安全策略,user没有写入权限,需要在vsftpd的配置文件中增加下列一项allow_writeable_chroot=YES
[root@server ~]# vim /etc/vsftpd/vsftpd.conf
allow_writeable_chroot=YES
再次验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:~> cd pub/
lftp 192.168.35.142:/pub> user user1
Password: 
lftp user1@192.168.35.142:~> ls
-rw-r--r--    1 0        0               0 Jul 23 01:43 file123

3、设置FTP用户访问FTP服务器时,将部分FTP用户访问的目录限制在自己的主目录中,
其他FTP用户仍然可以访问其他目录。
如果限制ftpuser1和ftpuser2用户访问的目录限制在自己的家目录中,user3可以访问其他目录
[root@server vsftpd]# vim vsftpd.conf
#chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
[root@server vsftpd]# vim chroot_list
user1
user2
[root@server vsftpd]# systemctl restart vsftpd

验证
[root@client ~]# lftp 192.168.35.142
lftp 192.168.35.142:~> user user1
Password: 
lftp user1@192.168.35.142:~> ls
-rw-r--r--    1 0        0               0 Jul 23 01:55 file123
lftp user1@192.168.35.142:/> cd ..
lftp user1@192.168.35.142:/> user user3
Password: 
lftp user3@192.168.35.142:~> ls
lftp user3@192.168.35.142:~> cd ..   
cd ok, cwd=/home
lftp user3@192.168.35.142:/home> ls
drwx------    2 1000     1000           62 Jul 11 01:54 lsy
drwx------    2 1001     1001           77 Jul 23 01:55 user1
drwx------    2 1002     1002           62 Jul 23 01:53 user2
drwx------    2 1003     1003           62 Jul 23 01:53 user3
lftp user3@192.168.35.142:/home> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值