33.vsftpd服务程序--本地用户模式

1.针对本地用户模式的权限参数以及作用如下

  

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
1 anonymous_enable=NO
2 local_enable=YES
3 write_enable=YES
4 local_umask=022
5 dirmessage_enable=YES
6 xferlog_enable=YES
7 connect_from_port_20=YES
8 xferlog_std_format=YES
9 listen=NO
10 listen_ipv6=YES
11 pam_service_name=vsftpd
12 userlist_enable=YES
13 tcp_wrappers=YES  
[root@localhost ~]# systemctl restart vsftpd
[root@localhost ~]# systemctl status vsftpd.service 
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-09-03 11:05:40 CST; 1s ago
  Process: 75088 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 75089 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─75089 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Sep 03 11:05:40 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
Sep 03 11:05:40 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.

  在 vsftpd 服务程序的主配置文件中正确填写参数,然后保存并退出。还需要重启vsftpd服务程序,让新的配置参数生效。最后将配置好的服务添加到开机启动项中,以便在系统重启自后依然可以正常使用vsftpd 服务。

[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

2.在使用root 管理员登录后,系统提示如下的错误信息:  

[root@localhost ~]# ftp 10.10.64.109
Connected to 10.10.64.109 (10.10.64.109).
220 (vsFTPd 3.0.2)
Name (10.10.64.109:root): root
530 Permission denied.
Login failed.
ftp> 

  在输入root 管理员的密码之前,就已经被系统拒绝访问了。这是因为vsftpd 服务程序所在的目录中默认存放着两个名为“用户名单”的文件(ftpusers 和user_list)。

  vsftpd 服务程序为了保证服务器的安全性而默认禁止了root 管理员和大多数系统用户的登录行为,这样可以有效地避免黑客通过FTP 服务对root 管理员密码进行暴力破解。如果确认在生产环境中使用root 管理员不会对系统安全产生影响,  只需删除掉root 用户名即可。  

[root@localhost ~]# 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@localhost ~]# 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账号和密码即可登录  

[root@localhost ~]# ftp 10.10.64.109
Connected to 10.10.64.109 (10.10.64.109).
220 (vsFTPd 3.0.2)
Name (10.10.64.109:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

3.选择ftpusers 和user_list 文件中没有的一个普通用户尝试登录FTP 服务器:    

[root@localhost ~]# ftp 10.10.64.109
Connected to 10.10.64.109 (10.10.64.109).
220 (vsFTPd 3.0.2)
Name (10.10.64.109:root): centos
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> mkdir files
550 Create directory operation failed.
ftp>   

  在采用本地用户模式登录FTP 服务器后,默认访问的是该用户的家目录,也就是说,访问的是/home/centos 目录。而且该目录的默认所有者、所属组都是该用户自己,因此不存在写入权限不足的情况。

  但是当前的操作仍然被拒绝,是因为需要开启SELinux 域中对FTP 服务的允许策略:  

[root@localhost ~]# getsebool -a | grep ftp
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_home_dir --> off
[root@localhost ~]# setsebool -P ftpd_full_access=on

  在设置SELinux域策略时,一定记得添加-P参数,否则服务器在重启后就会按照原有的策略进行控制,从而导致配置过的服务无法使用。在配置妥当后再使用本地用户尝试登录下FTP 服务器,分别执行文件的创建、重命名及删除等命令。操作均成功!

[root@localhost ~]# ftp 10.10.64.109
Connected to 10.10.64.109 (10.10.64.109).
220 (vsFTPd 3.0.2)
Name (10.10.64.109:root): centos
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> mkdir files
257 "/home/centos/files" created
ftp> rename files database
350 Ready for RNTO.
250 Rename successful.
ftp> rmdir database
250 Remove directory operation successful.
ftp> exit
221 Goodbye.
原文地址:https://www.cnblogs.com/xinghen1216/p/13729907.html