vsftpd搭建ftp服务,并实现虚拟用户访问
安装vsftpd服务:
使用本地用户登陆:
可以随意切换到任意目录
[root@wadeson vsftpd]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): ftp 匿名用户使用ftp就可以,密码为空
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 (127,0,0,1,70,12).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Jul 11 14:11 pub
drwxr-xr-x 4 14 50 4096 Jul 12 01:01 test
226 Directory send OK.
ftp> cd test
250 Directory successfully changed.
ftp> put /etc/inittab
local: /etc/inittab remote: /etc/inittab
227 Entering Passive Mode (127,0,0,1,103,252).
553 Could not create file.
ftp>
可以看出还是不能上传,但是可以创建文件
ftp> mkdir test02
257 "/test/test02" created
为啥可以创建文件,是因为在test目录下面的权限为:
[root@wadeson ftp]# ll test/
total 528
-rw-------. 1 ftp ftp 521169 Jul 12 09:00 2016-5.7z
drwx------. 2 ftp ftp 4096 Jul 12 09:00 test
drwx------. 2 ftp ftp 4096 Jul 12 09:01 test01
drwx------. 2 ftp ftp 4096 Jul 12 10:37 test02
-rw-------. 1 ftp ftp 1806 Jul 11 23:02 Tsgateway.RDP
现在使用ftp客户端工具匿名用户登陆:


可以看出这种情况下可以传输成功,但是ftp命令行下面一直却失败
现在将匿名的设置全部关闭掉,使用本地作限制:
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): wadeson
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 (127,0,0,1,244,146).
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/home/wadeson"
ftp> put /etc/inittab
local: /etc/inittab remote: /etc/inittab
227 Entering Passive Mode (127,0,0,1,125,218).
553 Could not create file. 这种方式传输文件还是不行
ftp> mkdir test
257 "/home/wadeson/test" created
ftp> ls
227 Entering Passive Mode (127,0,0,1,141,36).
150 Here comes the directory listing.
drwxr-xr-x 2 500 500 4096 Jul 12 02:44 test
226 Directory send OK.
但是这种方式传输又可以:

本地用户登陆可以随意切换目录,现在将它限制一下,只能在自己家目录访问:
只需要将chroot_local_user=YES这一行启用:
[root@wadeson vsftpd]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): wadeson
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 (127,0,0,1,71,18).
150 Here comes the directory listing.
-rw-r--r-- 1 500 500 521169 Jul 07 04:21 2016-5.7z
drwxr-xr-x 2 500 500 4096 Jul 12 02:44 test
226 Directory send OK.
ftp> cd /var
550 Failed to change directory.
现在将本地的用户切换目录做限制,哪些可以切换哪些不能切换:
将配置文件做如下修改:
#chroot_local_user=YES
chroot_list_enable=YES 启用列表文件中的本地用户不能切换目录
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list 将本地用户存在这个文件列表中,这个文件中存储了wadeson这个用户
现在进行测试:
root@wadeson vsftpd]# chmod 600 chroot_list
[root@wadeson vsftpd]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): wadeson
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 (127,0,0,1,223,113).
150 Here comes the directory listing.
-rw-r--r-- 1 500 500 521169 Jul 07 04:21 2016-5.7z
drwxr-xr-x 2 500 500 4096 Jul 12 02:44 test
226 Directory send OK.
ftp> pwd
257 "/"
ftp> cd /var
550 Failed to change directory.
然后更换一个本地用户:
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): test
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 (127,0,0,1,186,236).
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/home/test"
ftp> cd /var/
250 Directory successfully changed.
ftp> pwd
257 "/var"
发现可以随意切换目录,现在目的已经成功了
现在将本地用户做限制,一部分可以登陆ftp,一部分不能登陆:
配置如下:
userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list 在该文件中的本地用户都不能登陆ftp
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
向里面新增用户wadeson
然后测试:
[root@wadeson vsftpd]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): wadeson
530 Permission denied.
Login failed.
而另外一个刚刚创建的test用户依然可以登陆:
[root@wadeson vsftpd]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): test
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/test"
如果将userlist_deny=YES改为NO那么该/etc/vsftpd/user_list 中的本地用户可以登陆,没有存进去的用户则不能登陆
现在开始配置基于虚拟用户登陆的机制:
总共有七个步骤:
1、建立虚拟ftp用户的账号数据库文件
2、创建ftp根目录及虚拟用户映射的系统用户
3、建立支持虚拟用户的PAM认证文件
4、在vsftpd.conf文件中添加支持配置
5、为个别虚拟用户建立独立的配置文件
6、重新加载vsftpd配置
7、使用虚拟ftp账户访问测试
开始操作第一步:
1、建立虚拟ftp用户的账号数据库文件
建立虚拟账户的账户名和密码列表
[root@wadeson vsftpd]# vim vuser.txt
admin 账号
12345 密码
test 账号
12345 密码
将账号密码列表文件转化为db:
[root@wadeson vsftpd]# db_load -T -t hash -f vuser.list vuser.db
修改两个文件的权限:
[root@wadeson vsftpd]# chmod 600 vuser.*
-rw-------. 1 root root 12288 Jul 12 11:19 vuser.db
-rw-------. 1 root root 40 Jul 12 11:14 vuser.txt
2、创建ftp根目录及虚拟用户映射的系统用户
[root@wadeson ~]# mkdir /var/ftproot
drwxr-xr-x. 2 root root 4096 Jul 12 11:21 ftproot
创建一个系统用户用来被虚拟用户映射使用:
[root@wadeson var]# useradd -d /var/ftproot/ -s /sbin/nologin ftpuser 系统用户ftpuser
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[root@wadeson var]# cat /etc/passwd
ftpuser:x:502:502::/var/ftproot/:/sbin/nologin
[root@wadeson var]# chown ftpuser:ftpuser /var/ftproot/
drwxr-xr-x. 2 ftpuser ftpuser 4096 Jul 12 11:21 ftproot
3、建立支持虚拟用户的PAM认证文件
[root@wadeson var]# cd /etc/pam.d/
[root@wadeson pam.d]# vim vsftpd.vu
auth required pam_userdb.so db=/etc/vsftpd/vuser
account required pam_userdb.so db=/ets/vsftpd/vuser
4、在vsftpd.conf文件中添加支持配置
pam_service_name=vsftpd.vu
guest_enable=YES
guest_username=ftpuser
整个vsftpd.conf的配置内容:
anonymous_enable=NO
local_enable=YES
#write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
listen_port=21
userlist_enable=YES
chroot_local_user=YES
tcp_wrappers=YES
guest_enable=YES
guest_username=ftpuser (如果系统上没有该用户,需要创建)
pam_service_name=vsftpd.vu
user_config_dir=/etc/vsftpd/vsftpd_user_conf
virtual_use_local_privs=YES
pasv_min_port=50000
pasv_max_port=60000
pasv_enable=yes
max_clients=200
max_per_ip=4
idle_session_timeout=600
ftpd_banner=Welcome to opendoc FTP service.
write_enable=YES
anonymous_enable=NO
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_umask=022
download_enable=Yes
local_root=/var/ftproot 配置了chroot不能随意切换目录,整个admin虚拟用户权限为可创建可删除,可上传,可下载
配置另一个test用户: 该用户只能下载
vsftpd搭建ftp服务,并实现虚拟用户访问的更多相关文章
- 使用vsftpd 搭建ftp服务
ftp 基础服务器基础知识 ftp有三种登录方式.匿名登录(所有用户).本地用户.虚拟用户(guest). FTP工作模式 主动模式:服务端从20端口主动向客户端发起链接. 控制端口21:数据传输端口 ...
- CentOS7 FTP服务搭建(虚拟用户访问FTP服务)
概述 最近在搞Oracle在Linux系统下集群,针对Linux系统,笔人也是一片空白.Liunx外部文件的传输,避免不了使用FTP服务,所以现在就整理下,CentOS7环境下,FTP服务的搭建.FT ...
- FTP相关、用vsftpd搭建ftp、xshell使用xftp传输文件、使用pure-ftpd搭建ftp服务
1.FTP相关(file transfer protocol,文件传输协议) 2.用vsftpd搭建ftp安装:yum install vsftpd -y创建一个虚拟用户:useradd vft ...
- FTP 基础 与 使用 Docker 搭建 Vsftpd 的 FTP 服务
FTP 基础 与 使用 Docker 搭建 Vsftpd 的 FTP 服务 前言 最近的工作中,需要将手机上的文件发送到公司的 FTP 的服务器.按照从前的思路,自然是,先将文件传到电脑,再由电脑上传 ...
- 在Win7的IIS上搭建FTP服务及用户授权
FTP服务 FTP是文件传输协议(File Transfer Protocol)的简称,该协议属于应用层协议(端口号通常为21),用于Internet上的双向文件传输(即文件的上传和下载).在网络上有 ...
- 在Win7的IIS上搭建FTP服务及用户授权——转载!!
原文地址:http://blog.sina.com.cn/s/blog_6cccb1630100q0qg.html FTP服务 FTP是文件传输协议(File Transfer Protocol)的简 ...
- 【转】在Win7的IIS上搭建FTP服务及用户授权
[转]在Win7的IIS上搭建FTP服务及用户授权 [转]在Win7的IIS上搭建FTP服务及用户授权 FTP服务 FTP是文件传输协议(File Transfer Protocol)的简称,该协议属 ...
- exportfs命令、NFS客户端问题、FTP介绍、使用vsftpd搭建ftp
6月22日任务 14.4 exportfs命令14.5 NFS客户端问题15.1 FTP介绍15.2/15.3 使用vsftpd搭建ftp 14.4 exportfs命令 当我们修改nfs的配置文件e ...
- xshell使用xftp传输文件、使用pure-ftpd搭建ftp服务
6月25日任务 15.4 xshell使用xftp传输文件15.5 使用pure-ftpd搭建ftp服务扩展vsftp使用mysql存放虚拟用户并验证 http://www.aminglinux.co ...
随机推荐
- JS如何获取url查询字符串的键和值?
/** * 根据url查询字符串里的键名获取其值 */function getSearchString(key, search) { // 获取URL中?之后的字符 var str = search; ...
- Spring Cloud Feign 使用OAuth2
Spring Cloud 微服务架构下,服务间的调用采用的是Feign组件,为了增加服务安全性,server之间互相调用采用OAuth2的client模式.Feign使用http进行服务间的通信,同时 ...
- linux中常见命令操作(转)
1.日常操作命令 **查看当前所在的工作目录pwd **查看当前系统的时间 date **查看有谁在线(哪些人登陆到了服务器)who 查看当前在线last 查看最近的登陆历史记录 2.文件系统操作** ...
- Powershell替代和截断——replace and substring
一:截取一个字符串的尾部,替代字符串中的特定字符或替代字符串中特定位置的特定字符 $a="W.endy.chen.SHAO" $b=$a.Substring(0,$a.Length ...
- 装饰器模式(Decorator)
一.装饰模式介绍 装饰模式(decorator):表示动态的给一个对象添加一些新的功能(利用子类继承父类也可以实现),但是比生成子类方式更灵活. 也叫装饰者模式或者装饰器模式 例如:我们每个人身上穿的 ...
- glibc-2.23_int_malloc_流程浅析
- Yii框架2.0的Gii
Yii框架的Gii在我看来算是个快速创建器,当然对于学习来说意义不大,但对于已经懂得他的原理并用他开发的话,就是个快速开发的好工具. 他能快速的创建控制器,模块,crup,插件,Module. 打开g ...
- 【opencv】caffe 读入空图导致opencv错误
OpenCV Error: Assertion failed (ssize.area() > ) /modules/imgproc/src/imgwarp. 根据错误提示,查看一下opencv源 ...
- 【云安全与同态加密_调研分析(2)】国外云安全标准建议组织——By Me
国际上比较有影响力的云安全组织: ◆2. 国外云安全标准建议组织(云安全建议白皮书)◆ ◆云安全标准建议组织(主要的)◆ ◆标准建议组织介绍◆ ◆相关建议白皮书制定◆ ◆建立的相关模型参考◆ ◆备注( ...
- 2.AS入门教程
AndroidStudio 本文是关于androidStudio的一些基础知识 介绍 Google官方的Android集成开发环境(IDE = Integrated Development Envir ...