Detailed vsftpd service (anonymous users to access local user access, specify the user access control, virtual users)

Detailed vsftpd service (anonymous users to access local user access, specify the user access control, virtual users)

Detailed vsftpd

vsftpd is an abbreviation for "very secure FTP daemon", security is one of its greatest feature. vsftpd is the name of the server running on a UNIX-like operating system that can run on Linux, BSD, Solaris, HP- UNIX systems above, is such a completely free, open source ftp server software, supported by many other FTP server does not support features.
It features
a very high security requirements, bandwidth restrictions, good scalability, you can create virtual users, support for IPv6, the high rate of
small and light, easy to use security.

ftp, sftp, vsftp, vsftpd Detailed

ftp is an acronym for File Transfer Protocol, and File Transfer Protocol, a standard protocol for file transfer over the network, using a client / server model. It belongs to the application layer of the network transmission protocol.
sftp is an acronym for SSH File Transfer Protocol, secure file transfer protocol;
vsftp is based on the ftp server software used on the GPL release of Unix-like systems, which stands for Very Secure FTP can be seen from the name, the original intention of compilers is code security;
vsftpd is very secure FTP daemon acronym, security is one of its greatest feature. vsftpd is the name of the server running on a UNIX-like operating system that can run on, such as Linux, BSD, Solaris, HP- UNIX systems above, is a completely free, open source ftp server software;

Anonymous FTP user login

[root@localhost ~]# yum install vsftpd -y ##安装vsftp服务
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# systemctl start vsftpd  ##开启服务
[root@localhost vsftpd]# systemctl stop firewalld.service 
s[root@localhost vsftpd]# setenforce 0
[root@localhost vsftpd]# echo "this is text" > /var/ftp/test.txt ##写一段内容到测试文件中

Client access to test

C:\Users\CHEN>ftp 192.168.136.178 ##访问ftp服务
连接到 192.168.136.178。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): ftp  ##匿名访问
331 Please specify the password.
密码:  ##密码没有,直接回车
230 Login successful.
ftp> pwd  ##查看当前的绝对路径
257 "/"
ftp> ls -a  ##查看目录中的内容
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
.
..
pub
test.txt  ##服务器中的文件
226 Directory send OK.
ftp: 收到 25 字节,用时 0.00秒 25000.00千字节/秒。
ftp> get test.txt  ##下载文件到本地客户机,在哪个磁盘访问的就会下载到哪里,可以切换磁盘来下载
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for test.txt (13 bytes).
226 Transfer complete.
ftp: 收到 13 字节,用时 0.00秒 13000.00千字节/秒。

The client has not received the document View

Detailed vsftpd service (anonymous users to access local user access, specify the user access control, virtual users)

ftp> put test1.txt  ##创建一个文件上传到服务器中
200 PORT command successful. Consider using PASV.
550 Permission denied.  ##权限受限

Back to the server to open anonymous access permissions largest

[root@localhost ftp]# cd /etc/vsftpd/
[root@localhost vsftpd]# vim vsftpd.conf
##在配置文件中查找开启下列选项
anonymous_enable=YES       ##开启匿名用户
local_enable=YES    ##本地用户
write_enable=YES    ##写入权限
local_umask=022     ##本地用户反掩码
anon_upload_enable=YES   ##上传权限开启
anon_mkdir_write_enable=YES   ##开启创建目录并且能够写入
anon_other_write_enable=YES   ##添加一个other的重命名和删除的权限

[root@localhost vsftpd]# systemctl restart vsftpd  ##重启服务
[root@localhost vsftpd]# cd /var/ftp/    ##切换到ftp目录下
[root@localhost ftp]# ls
pub  test.txt
[root@localhost ftp]# ls -l
总用量 4
drwxr-xr-x. 2 root root  6 10月 31 2018 pub
-rw-r--r--. 1 root root 13 11月  5 19:14 test.txt
[root@localhost ftp]# chmod 777 pub   ##将pub目录权限给最大,注意不能直接给ftp权限最大

Then client to access ftp, upload local files to the server

C:\Users\CHEN>ftp 192.168.136.178 ##访问ftp服务
连接到 192.168.136.178。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): ftp
331 Please specify the password.
密码:
230 Login successful.
ftp> cd pub/                             ##切换到pub目录下
250 Directory successfully changed.
ftp> put test1.txt                      ##上传文件
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 发送 13 字节,用时 0.03秒 0.41千字节/秒。
ftp> by     ##退出
221 Goodbye.
##可以使用delete删除文件

Local users log on ftp file in the default home directory

root@localhost ~]# useradd zhangsan
[root@localhost ~]# passwd zhangsan
更改用户 zhangsan 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# useradd lisi
[root@localhost ~]# passwd lisi
更改用户 lisi 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

Prevent local users to access the system directory, restrict access to only the user's home directory

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf 
101 chroot_local_user=YES  ##第101行开启本地访问系统目录
102 chroot_list_enable=YES   ##102行添加写的权限
[root@localhost ~]# systemctl restart vsftpd

Access to the client to test

C:\Users\CHEN>ftp 192.168.136.178
连接到 192.168.136.178。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): zhangsan

331 Please specify the password.
密码:
230 Login successful.
ftp> cd /    ##切换到系统根目录
250 Directory successfully changed.
ftp> ls     ##查看发现还是在用户的家目录中,访问不到系统的其他目录了,增强了安全性
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.

Settings allow, deny specific users access to ftp

[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# vim vsftpd.conf

userlist_enable=YES ##确认user-list开启

[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# echo "zhangsan" >> user-list   ##将zhangsan用户添加到列表中,user-list(默认拒绝),允许或者拒绝特定用户登录
[root@localhost vsftpd]# systemctl restart vsftpd    ##重启服务

Access ftp client for testing

C:\Users\CHEN>ftp 192.168.136.178
连接到 192.168.136.178。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): zhangsan
530 Permission denied.
登录失败。                                        ##拒绝登录

Set list to allow only

[root@localhost ftp]# cd /etc/vsftpd/
[root@localhost vsftpd]# vim vsftpd.conf  ##配置vsftpd配置文件
userlist_enable=YES
userlist_deny=NO   ##添加列表允许

[root@localhost vsftpd]# systemctl restart vsftpd   ##重启服务

Client access to test

C:\Users\CHEN>ftp 192.168.136.178
连接到 192.168.136.178。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): zhangsan   ##用zhangsan去登录
331 Please specify the password.
密码:
230 Login successful.        ##登录成功
ftp> by
221 Goodbye.

C:\Users\CHEN>ftp 192.168.136.178
连接到 192.168.136.178。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.13.140:(none)): lisi       ##用lisi去登录
530 Permission denied.
登录失败。                           ##登录失败

The establishment of virtual users log in using ftp

File system in a user's home directory vuser

Create a virtual user file

[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# vim vuser

chen           ##奇数行为用户名
123123    ##偶数行为密码
cheng
123123

转换成数据库文件,设置权限

[root@localhost vsftpd]# db_load -T -t hash -f vuser vuser.db  ##将vuser转换成数据库文件,T转换,t类型,f指定文件
[root@localhost vsftpd]# chmod 600 vuser  ##设置权限
[root@localhost vsftpd]# chmod 600 vuser.db 

编辑pam认证模块支持虚拟用户登录
root@localhost vsftpd]# useradd -d /opt/vuser -s /sbin/nologin vuser  

Create a system user to specify home directory, you can not log in

[root@localhost vsftpd]# vim /etc/pam.d/vsftpd.vu   ##编译pam认证模块

auth required pam_userdb.so db=/etc/vsftpd/vuser    ##识别转换过的数据库文件
account required pam_userdb.so db=/etc/vsftpd/vuser   ##连接的密码服务
##开启虚拟用户,使用pam模块认证登录
[root@localhost vsftpd]# vim vsftpd.conf  ##修改配置文件
##大G到末行
#pam_service_name=vsftpd   ##注释
##添加下面三行内容
guest_enable=YES           ##开启来宾用户访问
guest_username=vuser      ##使用vuser用户名
pam_service_name=vsftpd.vu   ##pam模块
[root@localhost vsftpd]# systemctl restart vsftpd   ##重启服务

Client to test

C:\Users\xy007>ftp 192.168.136.178
连接到 192.168.136.178
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): tom   ##使用虚拟用户tom登录
331 Please specify the password.
密码:
230 Login successful.
ftp> put test1.txt      ##上传一个文件
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 发送 13 字节,用时 0.00秒 13000.00千字节/秒。
##查看文件的权限为600
[root@localhost vsftpd]# ls -l /opt/vuser/
总用量 4
-rw-------. 1 vuser vuser 13 11月  5 22:51 test1.txt

Single user configuration, designated permission to upload files 644

[root@localhost vsftpd]# vim vsftpd.conf 
##大G末行添加
user_config_dir=/etc/vsftpd/vu_dir   ##单独用户配置文件夹

[root@localhost vsftpd]# mkdir vu_dir  ##创建文件夹
[root@localhost vsftpd]# cd vu_dir/
[root@localhost vu_dir]# vim lisa     ##在配置文件夹里创建用户配置文件

anon_umask=022  ##指定上传文件的权限

[root@localhost vu_dir]# systemctl restart vsftpd  ##重启服务

Lisa client to test the use of user login, upload files to view permissions

C:\Users\xy007>ftp 192.168.136.178
连接到 192.168.136.178
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.136.178:(none)): lisa    ##使用lisa登录
331 Please specify the password.
密码:
230 Login successful.
ftp> put 111.txt        ##上传文件
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 发送 13 字节,用时 0.00秒 13000.00千字节/秒。

[root@localhost vu_dir]# ls -l /opt/vuser/   ##查看上传文件的权限
总用量 8
-rw-r--r--. 1 vuser vuser 13 11月  5 22:58 111.txt    ##lisa上传文件权限644
-rw-------. 1 vuser vuser 13 11月  5 22:51 test1.txt  ##tom上传文件权限600

Guess you like

Origin blog.51cto.com/14449524/2450659