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 ...
随机推荐
- 170411、java Socket通信的简单例子(UDP)
服务端代码: package com.bobohe.socket; import java.io.*; import java.net.*; class UDPServer { public stat ...
- freenas 11.2踩过的坑
修改SMB最小协议 服务器最小协议由FreeNAS上的sysctl控制. 在System-> Tunables 下添加sysctl来使其永久化:Variable = freenas.servic ...
- [iOS微博项目 - 3.6] - 获取未读消息
github: https://github.com/hellovoidworld/HVWWeibo A.获取登陆用户未读消息 1.需求 获取所有未读消息,包括新微博.私信.@.转发.关注等 把未 ...
- 用Python构建你自己的推荐系统
用Python构建你自己的推荐系统 现如今,网站用推荐系统为你提供个性化的体验,告诉你买啥,吃啥甚至你应该和谁交朋友.尽管每个人口味不同,但大体都适用这个套路.人们倾向于喜欢那些与自己喜欢的其他东西相 ...
- Python中的Numpy
引用Numpy import numpy as np 生成随机数据 # 200支股票 stock_cnt = 200 # 504个交易日 view_days = 504 # 生成服从正态分布:均值期望 ...
- Ubuntu 分区以及各个挂载目录的基本含义
我磁盘大概还有70多G的空间吧,我全部拿来使用的.真实的双系统哦. 一般来讲,linux系统分区最少要包括/和/swap两个.这样据说会影响性能,没有这样安装过,就无从考证啦.其实就是重装系统的时候, ...
- linux伙伴系统接口alloc_page分析1
在内核中分配内存,最后要通过伙伴系统接口进行实际物理页面的分配,一个重要的接口便是alloc_page.本文介绍下alloc_page的主要流程,各个部分的执行.主要包含正常分配流程,当页面不足的时候 ...
- Linux Anaconda安装步骤
首选下载wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh 可以去官网查看适合自己的文件https://www ...
- Python 能干什么
二.Python 只适合测试? 关于Python是一种什么样的语言,这里不打算说对象.类之类的术语.我们可以先来看一看,时至今日 Python 都在哪些领域里得以应用: 电信基础设施 (Twilio) ...
- mutex_lock
多核处理器下,会存在多个进程处于内核态的情况,而在内核态下,进程是可以访问所有内核数据的,因此要对共享数据进行保护,即互斥处理. mutex_lock(struct mutex *lock)和mute ...