文章目录
访问ftp【客户端】
这篇文章中ftp服务端已经过3万字数,再把客户端放这里面,内容过长,所以分开放。
点下面这文章链接,跳转至
ftp客户端使用详细说明【linux和windows】
ftp服务端配置【linux】
本文服务端是centos7.6的操作系统。
关闭防火墙和selinux
- 关闭防火墙
注意看后面命令说明
[root@centos76_2 ~]# systemctl is-active firewalld.service #查看
active
[root@centos76_2 ~]# systemctl stop firewalld.service #停止firewall
[root@centos76_2 ~]# systemctl disable firewalld.service #禁止firewall开机启动
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@centos76_2 ~]#
- 关闭selinux
注意看后面命令说明
[root@centos76_2 ~]# getenforce # 查看状态,Enforcing为开启
Enforcing
[root@centos76_2 ~]# vim /etc/selinux/config #编辑配置文件,修改后面参数,修改后为:SELINUX=disabled
# 这个修改后是需要重启生效的,但我们后面可以执行一个临时生效的,这样就可以不用重启了
[root@centos76_2 ~]# cat /etc/selinux/config | grep SELINUX= # 就是修改为如下效果
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@centos76_2 ~]#
[root@centos76_2 ~]# setenforce 0 #临时关闭linux
[root@centos76_2 ~]# getenforce # Permissive为关闭
Permissive
[root@centos76_2 ~]#
[root@centos76_2 ~]# /usr/sbin/sestatus -v # 查看selinux详细信息
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: disabled
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
Process contexts:
Current context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Init context: system_u:system_r:init_t:s0
/usr/sbin/sshd unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
File contexts:
Controlling terminal: unconfined_u:object_r:user_devpts_t:s0
/etc/passwd system_u:object_r:passwd_file_t:s0
/etc/shadow system_u:object_r:shadow_t:s0
/bin/bash system_u:object_r:shell_exec_t:s0
/bin/login system_u:object_r:login_exec_t:s0
/bin/sh system_u:object_r:bin_t:s0 -> system_u:object_r:shell_exec_t:s0
/sbin/agetty system_u:object_r:getty_exec_t:s0
/sbin/init system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0
/usr/sbin/sshd system_u:object_r:sshd_exec_t:s0
[root@centos76_2 ~]#
配置yum源【公网跳过该步骤】
首先上传一个和操作系统版本一致的镜像到服务器,我已经上传至/home
目录;
[root@centos76_2 home]# mkdir centos # 创建一个文件用来挂载镜像
[root@centos76_2 home]# mount CentOS-7.6-x86_64-DVD-1810.iso centos # 挂载镜像
[root@centos76_2 home]# df -h | tail -n 1 #查看挂载
/dev/loop0 4.3G 4.3G 0 100% /home/centos
[root@centos76_2 home]#
[root@centos76_2 yum.repos.d]# ls #默认会有很多文件夹
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@centos76_2 yum.repos.d]# mkdir bak #创建一个文件存放现有文件
[root@centos76_2 yum.repos.d]# mv * bak # 移动过去
[root@centos76_2 yum.repos.d]#
[root@centos76_2 yum.repos.d]# vim centos.repo # 创建一个新的yum源文件
[root@centos76_2 yum.repos.d]# cat centos.repo # 将下列内容复制进去保存即可
[7.6-bendi]
name=ccx_settin
baseurl=file:///home/centos
gpgcheck=0
enable=1
[root@centos76_2 yum.repos.d]#
[root@centos76_2 yum.repos.d]# yum repolist # 查看,repolist有内容即可
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
7.6-bendi ccx_settin 4,021
repolist: 4,021
[root@centos76_2 yum.repos.d]#
安装vsftp服务
下面命令照着执行一遍就好了
[root@centos76_2 yum.repos.d]# yum -y install vsftpd # 安装
[root@centos76_2 yum.repos.d]# systemctl is-active vsftpd #查看状态
unknown
[root@centos76_2 yum.repos.d]# systemctl start vsftpd # 启动
[root@centos76_2 yum.repos.d]# systemctl is-active vsftpd
active
[root@centos76_2 yum.repos.d]#
[root@centos76_2 yum.repos.d]# systemctl enable vsftpd # 加入开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@centos76_2 yum.repos.d]#
vsftp参数详细说明
vsftp的配置文件为:/etc/vsftpd/vsftpd.conf
[root@centos76_2 yum.repos.d]# cat /etc/vsftpd/vsftpd.conf | grep -v "^#" #查看默认开启的服务
anonymous_enable=YES #不允许匿名访问
local_enable=YES #默认启用
write_enable=YES #允许写入
local_umask=022 # 默认本地用户上传文件权限755
dirmessage_enable=YES #显示每个目录下的文件信息
xferlog_enable=YES # 日志启用
connect_from_port_20=YES # 主动请求的数据端口
xferlog_std_format=YES #。。。
listen=NO #服务将自己监听下面内容【listen_ipv6=YES】
listen_ipv6=YES #上面listen为NO,这个没作用
pam_service_name=vsftpd # 设置PAM认证模块使用的预览名称
userlist_enable=YES #所有文件列出用户
tcp_wrappers=YES # 服务端和客户端访问控制策略【服务级别的一种防火墙】
#除了上面自带的功能外,常用重要配置还有如下几个
chown_uploads=YES #所有匿名用户上传的文件所属用户将会被改成chown_username
chown_username=whoname #匿名上传的所属用户名是whoname【需要和上面一条配套使用】
xferlog_stad_format=YES #启用日志
xferlog_file=/var/log/xferlog#启用的日志文件【需要和上面一条配套使用】
local_root=/data/ccx # 修改默认家路径
idle_session_timeout=600 #空闲连接超时
data_connection_timeout=120 #数据连接超时
nopriv_user=ftpsecure #当服务器运行与最底层时使用的用户名
chroot_local_user=YES #不可以切换到其他用户
chroot_list_file=/etc/vsftpd/chroot_list #只允许该文件中的用户登陆ftp,和上面一个配套使用
[root@centos76_2 yum.repos.d]#
- 上面基本是常用的配置了,测试demo中我基本上只对上面中做说明,但只要知道怎么配置以后,下面的功能要的直接拿来用就行了;
- 在这儿整理了更多 更详细的内容,编辑文件均在:
/etc/vsftpd/vsftpd.conf
里面anonymous_enable=YES
/允许匿名访问 12行local_enable=YES
/允许本地用户访问(/etc/passwd中的用户) 15行write_enable=YES
/允许写入权限,包括修改,删除 18行local_umask=022
/本地用户文件上传后的权限是-rw-r–r-- 22行
本地用户上传最高权限为666,默认权限为666-022=644,即local_umask=022anon_umask=022
/默认没有这一项【了解即可】,匿名用户上传后的权限是-rw-------。匿名用户上传的默认权限为600,即anon_umask=066,匿名用户上传最大权限是666,这里权限是用666-022=644方法得来的-rw-r–r-anon_world_readable_only=YES
/允许匿名用户浏览,下载文件,默认没有这一项,只有在虚拟用户的配置文件里才有用anon_upload_enable=YES
/默认注释掉了,允许匿名用户上传 27行anon_mkdir_write_enable=YES
/默认注释掉了,允许匿名用户上传/建立目录 31行anon_other_write_enable=YES
/默认没有这一项,允许匿名用户具有建立目录,上传之外的权限,如重命名,删除dirmessage_enable=YES
/是否显示目录说明文件, 默认是YES 但需要手工创建.message文件,这个.message,只有用命令登陆或者用工具,才可以看见,他不是一个弹出对话框,而是一段字符,如在pub下建立一个.message,那么在客户端进入pub目录时就会显示.message文档中的内容 35行xferlog_enable=YES
/记录使用者所有上传下载信息 38行chown_uploads=YES
/默认注释了,开启匿名用户上传用户映射,和下面一行一起使用 48行chown_username=whoever
/默认注释了,将匿名用户上传的文件的用户映射为whoever用户 49行xferlog_file=/var/log/vsftpd.log
/默认注释掉了这一项 51行
#将上传下载信息记录到/var/log/vsftpd.log中connect_from_port_20=YES
#确保ftp-datad 数据传送使用port 20(20号端口)idle_session_timeout=600
/默认注释掉了这一项 58行
#如果使用者600秒没有动作,则强制离线,也就是指令超时时间,data_connection_timeout=120
/如果 client与 Server 间的数据传送在 120 秒内都无法传送成功,那 Client的联机就会被我们的 vsftpd 强制剔除! 62行ftpd_banner=Welcome to blahFTP service.
/ftp的欢迎信息 84行banner_file=/etc/vsftpd/banner_file.txt
/默认没有这一项,ftp的欢迎信息
#欢迎信息存放在banner_file.txt文件中,如果添加中文欢迎信息,就需要在xp中将此文件编辑好后上传到/etc/vsftpd 目录中。如果ftpd_banner和banner_file同时设置,那么banner_file将覆盖ftpd_banner的设置。Listen_address=10.1.6.0
/默认没有这一项,禁止10.1.6.0段访问此FTPchroot_list_enable=YES
/禁固宿主目录,默认这一项注释掉了 95行
#限制使用者不能离开家目录,例如blue登陆后位于/home/blue下,设置该选项后,他不可以转到/home/blue的上层目录,如/bin, /usr,/opt…etc。chroot_list_file=/etc/vsftpd/chroot_list
/默认这一项注释掉了
#与上条同时使用,设置要禁固宿主目录的用户的配置文件为/etc/vsftpd/chroot_list 建立文本文件/etc/vsftpd/chroot_list,写入要禁固宿主目录的用户,一行一个。当chroot_list_enable=YES时,则禁固chroot_list文件里面的用户的宿主目录,而为NO时chroot_list文件里面的用户不禁固宿主目录。tcp_wrappers=YES
/默认没有这一项
#支持tcp_wrappers,限制访问(/etc/hosts.allow,/etc/hosts.deny)xferlog_std_format=YES
listen=YES /109行
#使用standalone启动vsftpd,而不是super daemon(xinetd)控制它 (vsftpd推荐使用standalone方式) 108行listen_port=21
/默认没有这一行 #ftp监听端口pam_service_name=vsftpd
/116行
#PAM所使用的名称.同userlist_*一样限制用户登陆,不同的是userlist_*在进行密码验证之前拒绝用户登陆,pam是在密码验证之后拒绝登陆.(提示密码错误) 用户列表默认存放在/etc/vsftpd/ftpusers中,一行一个. (可通过/etc/pam.d/vsftpd重定向用户列表存放文件)
#获得 /etc/pam.d/vsftpd:
#[root@LFSvsftpd-2.0.1]#cp RedHat/vsftpd.pam/etc/pam.d/vsftpduserlist_enable=YES
/ 为yes时, /etc/vsftpd/user__list文件中的用户将不能访问vsftpd服务器 117行userlist_deny=YES
/默认没有这一项,与下面这条参数:userlist_file=/etc/vsftpd/localuser_list
结合使用。
userlist_file=/etc/vsftpd/localuser_list
/默认没有这一项, 与上面参数:userlist_deny=YES结合使用此参数用,来改变存放可以登录或禁止登录的账号,suerlist_deny为YES时,这里面的用户则不能登录,当为NO时,这里面的用户可以登录,和/etc/vsftpd/user_list是一个意思max_clients=100
/默认没有这一项
#最大用户在线数量max_per_ip=2
/默认没有这一项
#每ip最大线程anon_max_rate=30000
/默认没有这一项
#匿名用户最大传输速度 单位: bytes/秒local_max_rate=50000
/默认没有这一项
#本地用户最大传输速度 单位:bytes/秒user_config_dir=/etc/userconf
/默认没有这一项
#个别用户配置目录(用来设定特殊帐号),例如我想让blue这个用户的传输速度是100KB
就可以在/etc/userconf/下创建文本文件blue(与用户名相同),加入local_max_rate=100000即可 /默认没有这一项anon_root=/var/ftp
/默认没有这一项
#设定匿名用户登陆后所在的目录local_root=/var/local_user
/默认没有这一项
#设定所有本地用户登陆后的目录,如不设置此项,则本地用户登陆后位于各自家目录下。use_localtime=YES
/默认没有这一项
#使用本地时间而不是GMTnopriv_user=vsftpd
/默认没有这一项
指定vsftpd服务的运行帐户,不指定时使用ftp
vsftp配置
前提准备
当前服务端虚拟机ip为:192.168.59.129
vsftp默认存放路径地址为:/var/ftp/pub
然后在这个文件中继续创建文件夹或文件即可。
在这个路径下创建几个文件【file为文件夹,test为文件】
[root@centos76_2 ~]# cd /var/ftp/pub/
[root@centos76_2 pub]# ls
[root@centos76_2 pub]# mkdir file{1..3}
[root@centos76_2 pub]# touch test{1..3}
[root@centos76_2 pub]# ls
file1 file2 file3 test1 test2 test3
[root@centos76_2 pub]#
[root@centos76_2 pub]# echo cat << e > test1
> test1
> hello test1
> e
[root@centos76_2 pub]# echo cat << e > test2
> test2
> god test2
> e
[root@centos76_2 pub]#
打开就可以看到了哦【不要急打开方式这些,我后面会做说明,只是让你知道而已】
注:其实路径用/var/ftp
就可以了,但因为pub是默认生成的,也代表了公共文件,所以一般默认放/var/ftp/pub
里面了,也可以在/var/ftp
里面创建文件,和pub一样作为基层文件使用的,如下图
服务检查
下面3项如果有问题,会导致ftp无法正常使用。
- 1、检查 vsftpd服务是不是正常开启
- 2、检查防火墙是否关闭【如果防火墙有放开策略了,关不关无所谓】
- 3、selinux是否关闭
[root@centos76_2 pub]# systemctl is-active vsftpd
active
[root@centos76_2 pub]# systemctl is-active fir
firewalld.service firstboot-graphical.service
[root@centos76_2 pub]# systemctl is-active fir
firewalld.service firstboot-graphical.service
[root@centos76_2 pub]# systemctl is-active firewalld.service
unknown
[root@centos76_2 pub]# getenforce
Permissive
[root@centos76_2 pub]#
所有用户生效的常用功能
对于所有用户默认生效一般也就能否上传和能否删除而已,其他就不多做说明了。
上传功能配置
未配置时是无法拷贝文件的
- 1、 修改配置文件
/etc/vsftpd/vsftpd.conf
相关选项
[root@centos76_2 pub]# vim /etc/vsftpd/vsftpd.conf
anon_umask=022 #增加
anon_upload_enable=YES #取消注释,在29行
anon_mkdir_write_enable=YES #取消注释,这33行
-
2、重启vsftpd服务
[root@centos76_2 pub]# systemctl restart vsftpd
-
3、修改目录
/var/ftp/pub
权限,给目录写权限
[root@centos76_2 pub]# chmod 777 /var/ftp/pub/
-
4、上传文件测试
Windows打开我的电脑,文件路径处输入ftp://ip
,进入pub目录底下上传【拷贝】文件
删除功能配置
配置前删除是会报错的
1、修改配置文件/etc/vsftpd/vsftpd.conf
相关选项
[root@centos76_2 pub]# vim /etc/vsftpd/vsftpd.conf
#最后一行添加如下内容
anon_other_write_enable=YES
[root@centos76_2 pub]# tail -n 1 /etc/vsftpd/vsftpd.conf
anon_other_write_enable=YES
[root@centos76_2 pub]#
2、重启vsftpd服务测试
[root@centos76_2 pub]# systemctl restart vsftpd
3、删除文件测试
Windows打开我的电脑,文件路径处输入ftp://ip
,进入pub目录底下删除文件
本地用户生效配置
- 不知道有没有必要解释下本地用户生效的意思
- 就是说 下面功能仅对 服务端上的用户生效,不是服务端上的用户名,一律阻止【不允许访问】
- 查看本地用户,目录:
/etc/passwd
# 在服务端虚拟机上查看,这种就是普通用户
[root@centos76_2 pub]# tail -n 3 /etc/passwd
ccx:x:1000:1000:ccx:/home/ccx:/bin/bash
ccx1:x:1001:1001::/home/ccx1:/bin/bash
ccx2:x:1002:1002::/home/ccx2:/bin/bash
[root@centos76_2 pub]#
创建本地ftp用户
useradd username -s /sbin/nologin
# 创建 只允许ftp登陆的用户名- 注: 查看路径为:
/etc/passwd
,如下面ccx和ccx2用户编译器为:/sbin/nologin
[root@centos76_2 ccx]# tail -n 4 /etc/passwd
ccx:x:1000:1000::/home/ccx:/sbin/nologin
ccx1:x:1001:1001::/home/ccx1:/bin/bash
ccx2:x:1002:1002::/home/ccx2:/sbin/nologin
ccx3:x:1003:1003::/home/ccx3:/bin/bash
[root@centos76_2 ccx]#
- 如果无法通过/sbin/nologin用户登陆,一直报530认证失败,但普通用户却可以正常登陆
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
原因:vsftpd默认会检查用户的shell,如果用户的shell在/etc/shells没有记录,则无法登陆ftp
解决办法:在服务端的/etc/shells
文件里面添加用户的shell(解释器)
vim /etc/shells
#添加一行/sbin/nologin
即可
关闭匿名登陆功能
- 1、修改主配置文件
/etc/vsftpd/vsftpd.conf
开启本地用户权限(关闭匿名用户)
[root@centos76_2 pub]# vim /etc/vsftpd/vsftpd.conf
#将下面这个的YES改为NO
anonymous_enable=NO
上面配置文件中的YES改为NO重启vsftpd服务以后,再次访问就需要让登陆了(Windows访问)。
- 2、修改权限
如果你是能够链接到FTP 但是看不到文件 上传和下载都没有办法做出操作,再做下面操作
执行getsebool -a | grep ftp
,可以看到下面红圈中2个为off
状态
执行2个命令将她们开启:
[root@centos76_2 pub]# setsebool -P allow_ftpd_full_access on
[root@centos76_2 pub]# setsebool -P sftp_home_dir on
开启后状态就为on了
开启上传、下载、删除功能
[root@centos76_2 ccx]# vim /etc/vsftpd/vsftpd.conf
write_enable=YES
[root@centos76_2 ccx]# systemctl restart vsftpd
注:关闭匿名登陆以后,默认目录不在是/var/ftp/put
了,而是 用户的目录【/home中,比如ccx用户,则默认目录就是/home/ccx
】,关闭匿名登陆以后,访问方法是ftp://ip
进去默认就是家目录,如果后面跟路径了,可能就回报550权限问题了【限windows】
测试
我先在ccx家目录中创建一些文件,可以看到ccx用户的编译器是nologin的哦。
打开windows,输入:ftp://ip
,输入用户名和密码
登陆以后就可以看到了这些文件了
上传下载删除新建都是可以正常使用的
敲黑板,注意,我上面说过这段话,如果没注意看,可能就会产生下面错误了
我现在访问在位置栏输入:/ftp://ip/pub/
访问就会报下面的550错误,这个是无法解决的!!!
修改默认家目录
如果不修改的话,我们通过不同用户登陆进去的,都是在这个用户的家目录里面【比如:/home/ccx, /home/ccx1, /home/ccx2】
但是修改了这个默认家目录以后,所有的用户登陆进去都在这个指定目录里面了。
这个不建议配置,除非你知道自己的在干什么。
一般情况都是不修改默认目录,但开启目录限制,就是每个用户登陆进去只能看到自己家目录的内容不能切换到其他目录【一般在linux上可以体现,linux可以cd切换目录,下面有说明】
新增行: local_root=/data/ccx
#后面/data/ccx为路径
为路径根文件设置777权限,否则后面会无法操作:chmod 777 -R /data
【家目录不用是修改是因为家目录默认777权限】
[root@centos76_2 ccx]# vim /etc/vsftpd/vsftpd.conf
# 新增在任意位置即可
local_root=/data/ccx
allow_writeable_chroot=YES #2.3.5之后,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了,需新增此配置
[root@centos76_2 ccx]# mkdir -p /data/ccx #创建默认目录
[root@centos76_2 ccx]# chmod 777 -R /data
[root@centos76_2 ccx]#
[root@centos76_2 ccx]# touch /data/ccx/test{1..3} #创建几个默认文件夹测试用
[root@centos76_2 ccx]# ls /data/ccx/
test1 test2 test3
[root@centos76_2 ccx]#
[root@centos76_2 ccx]# systemctl restart vsftpd
测试
我使用ccx1这个用户测试,我先在这个家目录下创建几个文件,以便于后面区别是否配置成功
[root@centos76_2 ccx]# cd
[root@centos76_2 ~]# touch /home/ccx1/ccx1{1..3}
[root@centos76_2 ~]# ls /home/ccx1
ccx11 ccx12 ccx13
我们在地址栏把这个/
去掉回车就可以重新登陆了哦【windows】
登陆 ccx1
登陆进来以后看到是test文件【如果不是可以尝试刷新一下当前页面】,修改成功,2个文件夹是刚才创建的【有操作权限】
如果不修改权限为777的话,就无法创建文件这些操作了【刚去把权限改为755了】
linux上也是正常查看的,只是目录变成/
了
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx1
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 (192,168,59,129,199,12).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 06 04:03 test1
-rw-r--r-- 1 0 0 0 May 06 04:03 test2
-rw-r--r-- 1 0 0 0 May 06 04:03 test3
226 Directory send OK.
ftp> pwd
257 "/"
ftp>
目录限制配置
默认情况当前用户登陆ftp后可以来回切换文件系统,如果开启,就不能来回切换目录,只能查看编辑当前目录内容了。
这个需要用linux做测试了,未修改前如下,可以正常切换所有目录
[root@centos76_1 ~]# ftp 192.168.59.129 #登陆
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx # 输入用户名
331 Please specify the password.
Password: #输入密码
230 Login successful. #登陆成功提升
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd #默认家目录
257 "/home/ccx"
ftp> cd /var/ftp/ #可以切换目录
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,59,129,56,40).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Apr 30 04:04 file_test
drwxrwxrwx 5 0 0 84 Apr 30 09:31 pub
226 Directory send OK.
ftp> cd pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,59,129,187,216).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Apr 30 03:56 file1
drwxr-xr-x 2 0 0 6 Apr 30 03:56 file2
drwxr-xr-x 2 0 0 6 Apr 30 03:56 file3
-rw-r--r-- 1 0 0 34 Apr 30 09:03 test1
-rw-r--r-- 1 0 0 4 Apr 30 03:57 test2
-rw-r--r-- 1 0 0 0 Apr 30 03:56 test3
226 Directory send OK.
ftp> get test1 # 可以下载其他目录中的文件
local: test1 remote: test1
227 Entering Passive Mode (192,168,59,129,85,16).
150 Opening BINARY mode data connection for test1 (34 bytes).
226 Transfer complete.
34 bytes received in 0.000346 secs (98.27 Kbytes/sec)
ftp>
- 配置
- 增加内容为:开启chroot选项
allow_writeable_chroot=YES
- 取消注释 指定本地用户不能翻目录
chroot_local_user=YES
- 增加内容为:开启chroot选项
[root@centos76_2 ccx]# vim /etc/vsftpd/vsftpd.conf
#大概在102行,取消注释下列行内容,我是在取消注释前面添加的这个行呢
# 快速跳到102行的方法,vim进去以后,按102再按G即可,临时开启行号显示,:set nu
# 前面的102序号是行号,不要加啊!
102 allow_writeable_chroot=YES
103 chroot_local_user=YES
[root@centos76_2 ccx]# systemctl restart vsftpd
上面这样说这样能看懂吗? 如下图,102行是我新增的,103行是我取消注释的。
测试
上面步骤做完以后,我们再次使用ftp登陆该服务器,可以看到登陆进去以后,目录变成/
了,而非家目录全程,并且再次切换目录就会报550错误呢,配置完成。
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
227 Entering Passive Mode (192,168,59,129,230,53).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 May 06 03:29 home_ccx
drwxr-xr-x 2 1000 1000 6 May 06 03:34 新文件夹
drwxr-xr-x 2 1000 1000 6 May 06 03:34 新文件夹 (2)
226 Directory send OK.
ftp> cd /etc/
550 Failed to change directory.
ftp>
注:上面新增的行,不要敲错代码了,如果敲错以后,登陆会变成如下样子,并且是无法做任何操作的。
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx
331 Please specify the password.
Password:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
421 Service not available, remote server has closed connection
ftp>
ftp> ls
Not connected.
只允许用户列表中用户切换目录【白名单】
-
说明,这个功能不是说只允许列表中用户登陆ftp,而是说列表中的用户不受功能限制,比如下面限制了本地用户不能翻目录,但列表中的用户依然是可以翻目录的【其他用户只能登陆到家目录不能切换其他目录】,就是这样,之前我以为是这个只允许列表中用户登陆ftp,其他用户无法登陆,折腾了很久,发现是我理解错了。
-
chroot_list_enable=YES
开启代表用户列表文件/etc/vsftpd/chroot_list
中的用户可以访问【需要在/etc/vsftpd
目录下创建文件chroot_list
,在文件中写入用户名,一行一个用户】,未在文件中列出的用户不能访问 -
需要修改3处
- 首先开启chroot选项,添加:
allow_writeable_chroot=YES
【已添加忽略】 - 取消注释 指定本地用户不能翻目录 ,
chroot_local_user=YES
- 最后取消注释,指定用户列表文件的用户可以访问
chroot_list_enable=YES
#和上面是配套使用的
- 首先开启chroot选项,添加:
[root@centos76_2 ~]# vim /etc/vsftpd/vsftpd.conf
103 allow_writeable_chroot=YES
104 chroot_local_user=YES
105 chroot_list_enable=YES
[root@centos76_2 ~]# systemctl restart vsftpd
[root@centos76_2 ~]# cd /etc/vsftpd/
[root@centos76_2 vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@centos76_2 vsftpd]# vim chroot_list # 创建允许登陆的用户
hero1
hero2
[root@centos76_2 vsftpd]# useradd -s /sbin/nologin hero1 #创建用户名和密码
[root@centos76_2 vsftpd]# useradd -s /sbin/nologin hero2
[root@centos76_2 vsftpd]# echo hero1|passwd --stdin hero1
Changing password for user hero1.
passwd: all authentication tokens updated successfully.
[root@centos76_2 vsftpd]# echo hero2|passwd --stdin hero2
Changing password for user hero2.
passwd: all authentication tokens updated successfully.
[root@centos76_2 vsftpd]#
测试
注意看命令中的说明
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx #先登陆未在列表中的用户
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 (192,168,59,129,122,26).
150 Here comes the directory listing.
-rwxrwxrwx 1 0 0 0 May 06 04:03 test1
-rw-r--r-- 1 0 0 0 May 06 04:03 test2
-rw-r--r-- 1 0 0 0 May 06 04:03 test3
226 Directory send OK.
ftp> cd /var/ftp #切换路径会报错
550 Failed to change directory.
ftp> ls
227 Entering Passive Mode (192,168,59,129,244,220).
150 Here comes the directory listing.
-rwxrwxrwx 1 0 0 0 May 06 04:03 test1
-rw-r--r-- 1 0 0 0 May 06 04:03 test2
-rw-r--r-- 1 0 0 0 May 06 04:03 test3
226 Directory send OK.
ftp> 221 Goodbye.
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): hero1 # 登陆在列表中的用户
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 (192,168,59,129,56,190).
150 Here comes the directory listing.
-rwxrwxrwx 1 0 0 0 May 06 04:03 test1
-rw-r--r-- 1 0 0 0 May 06 04:03 test2
-rw-r--r-- 1 0 0 0 May 06 04:03 test3
226 Directory send OK.
ftp> cd /var/ftp # 能正常切换目录
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,59,129,19,221).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Apr 30 04:04 file_test
drwxrwxrwx 5 0 0 84 Apr 30 09:31 pub
226 Directory send OK.
ftp>
扩展说明
- 在默认配置下,本地用户登入FTP后可以使用cd命令切换到其他目录,这样会对系统带来安全隐患。可以通过以下三条配置文件来控制用户切换目录。
chroot_list_enable=YES/NO
#设置是否启用chroot_list_file配置项指定的用户列表文件。默认值为NO。
用户名存放文件:/etc/vsftpd.chroot_list
,一行一个白名单用户,用于指定用户列表文件,该文件用于控制哪些用户可以切换到用户家目录的上级目录。chroot_local_user=YES/NO
#用于指定用户列表文件中的用户是否允许切换到上级目录。默认值为NO。- 通过搭配能实现以下几种效果:
- ①当
chroot_list_enable=YES,chroot_local_user=YES
时,在/etc/vsftpd.chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录。 - ②当
chroot_list_enable=YES,chroot_local_user=NO
时,在/etc/vsftpd.chroot_list文件中列出的用户,不能切换到其他目录;未在文件中列出的用户,可以切换到其他目录。 - ③当
chroot_list_enable=NO,chroot_local_user=YES
时,所有的用户均不能切换到其他目录。 - ④当
chroot_list_enable=NO,chroot_local_user=NO
时,所有的用户均可以切换到其他目录。
- ①当
禁止某些用户登陆
/etc/vsftpd/ftpusers
这个是系统默认的黑名单,这里面的用户也是直接被拒绝的,但我们不用这种方法,用其他方法,继续往下看。
- 额,就是不想让某些用户访问ftp
- 命令说明
userlist_deny=YES
/默认没有这一项,与下面这条参数:userlist_file=/etc/vsftpd/localuser_list
结合使用。
userlist_file=/etc/vsftpd/localuser_list
/默认没有这一项, 与上面参数:userlist_deny=YES结合使用此参数用,来改变存放可以登录或禁止登录的账号,suerlist_deny为YES时,这里面的用户则不能登录,当为NO时,这里面的用户可以登录,和/etc/vsftpd/user_list是一个意思
- 过程见下面,后面说明,不懂就认真看。
[root@centos76_2 userconfig]# vim /etc/vsftpd/vsftpd.conf
# 我是在最后添加的下面2行
userlist_deny=YES
userlist_file=/etc/vsftpd/localuser_list
[root@centos76_2 vsftpd]# systemctl restart vsftpd
[root@centos76_2 userconfig]# cd /etc/vsftpd/
[root@centos76_2 vsftpd]# vim localuser_list #创建不允许登陆的用户名,一行一个
ccx
superman1
测试
因为上面限制了ccx和superman1不能正常登陆,所以我登陆这2个用户直接连输密码的机会都不给我。
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx #输入用户名就结束了
530 Permission denied.
Login failed.
ftp> ls
530 Please login with USER and PASS.
Passive mode refused.
ftp> 221 Goodbye.
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): superman1 #输入用户名就结束了
530 Permission denied.
Login failed.
ftp> ls
530 Please login with USER and PASS.
Passive mode refused.
ftp>
这放一个正常的康康
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): ccx1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 221 Goodbye.
配置多用户登陆
- 这个功能可能有点鸡肋,就是为了不同用户登陆进去进入到不同的路径,和不指定默认家目录唯一不同的区别就是这个可以指定路径罢了。
- 注:我当前ftp已经配置了默认家目录
- 配置
命令:新增一行user_config_dir=/etc/vsftpd/userconfig
#用户配置目录【多用户的时候,设置各个用户登录自己的目录】
mkdir创建/etc/vsftpd/userconfig文件夹,然后在文件夹中vim编辑需要配置的用户名,内容是:local_root=/file
【口述的过程,看不懂不要紧,下面命令有详细过程 】 - 过程看命令介绍吧,跟着命令流程走
[root@centos76_2 vsftpd]# vim vsftpd.conf
# 我是在最后新增的下面行内容
user_config_dir=/etc/vsftpd/userconfig
[root@centos76_2 vsftpd]# systemctl restart vsftpd
[root@centos76_2 vsftpd]# cd /etc/vsftpd
[root@centos76_2 vsftpd]# mkdir userconfig
[root@centos76_2 vsftpd]# cd userconfig
[root@centos76_2 userconfig]# vim superman1 #superman1是用户名
#这个命令其实就是修改默认家目录的命令,后面是自定义路径
local_root=/ftp/superman1
[root@centos76_2 userconfig]# vim superman2 #superman2是用户名
#这个命令其实就是修改默认家目录的命令,后面是自定义路径
local_root=/ftp/superman2
[root@centos76_2 userconfig]# useradd -s /sbin/nologin superman1 #创建用户名
[root@centos76_2 userconfig]# useradd -s /sbin/nologin superman2 #创建用户名
[root@centos76_2 userconfig]# echo superman1 | passwd --stdin superman1 # 设置密码
Changing password for user superman1.
passwd: all authentication tokens updated successfully.
[root@centos76_2 userconfig]# echo superman2 | passwd --stdin superman2
Changing password for user superman2.
passwd: all authentication tokens updated successfully.
[root@centos76_2 userconfig]#
[root@centos76_2 userconfig]# mkdir -p /ftp/superman1 #创建路径文件
[root@centos76_2 userconfig]# mkdir -p /ftp/superman2 #创建路径文件
[root@centos76_2 userconfig]# touch /ftp/superman1/superman{1..3} #创建几个文件,便于测试是否成功
[root@centos76_2 userconfig]# touch /ftp/superman2/superman{4..6}
[root@centos76_2 userconfig]#
测试
登陆superman1
内容是刚创建的【如果内容没变,可以刷新该页面】,成功。
superman2我用linux登陆
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 (vsFTPd 3.0.2)
Name (192.168.59.129:root): superman2 # 登陆
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 (192,168,59,129,97,210).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 06 10:19 superman4
-rw-r--r-- 1 0 0 0 May 06 10:19 superman5
-rw-r--r-- 1 0 0 0 May 06 10:19 superman6
226 Directory send OK.
ftp> cd /etc/ # 这个是不能切换路径的,如果要切换路径,把这个用户名加到上面配置的白名单列表中哈
550 Failed to change directory.
ftp>
注:除了刚才创建的superman1和superman2用户,其他用户都是前面的默认家目录而非自定义目录呢,测试
登陆进来是这样的
21端口修改为区间【修改一个也说明】
-
修改默认21简单的多,直接添加下面这行,后面21改为想修改的端口即可
listen_port=21
/默认没有这一行 #ftp监听端口 -
如字面意思,修改端口。不知道自己在干嘛不要操作这个,否则会导致ftp没法使用。
-
最后一行添加如下3行即可
pasv_enable=YES
pasv_min_port=59601
pasv_max_port=59611
【vsftpd被动模式配置,命令端口21 控制端口59601-59611】
[root@centos76_2 vsftpd]# vim vsftpd.conf
# 可以添加在最后一行,初始端口和结尾端口自定义
pasv_enable=YES
pasv_min_port=59601
pasv_max_port=59611
[root@centos76_2 vsftpd]# systemctl restart vsftpd
游客用户【虚拟用户】
说明
-
在linux,使用vsftp建立用户后,默认使用ftp访问的时候,是访问对应的用户家目录。想要多个用户同时访问一个目录,同时对同一目录有着不同的权限,这些设定只能通过vsftp中的虚拟用户来进行设定,普通用户无法达到这样的效果。
-
配置过程:
首先通过建立一个普通系统用户,建立家目录,然后将所有的虚拟用户映射到对应的普通系统用户家目录,然后对各虚拟用户进行权限控制,虚拟用户没有查看目录的权限。
配置【demo说明】
- 这里我以一个测试做说明,原理会了,用户功能增删改就行;
- 要求
- yb1只能进行下载
- yb2能进行下载和上传
- 对下载/上传流量进行控制
配置过程
(1)操作虚拟用户列表并生成认证文件
- 建立虚拟用户的用户名、密码列表的文本文件
[root@centos76_2 vsftpd]# vim /etc/vsftpd/vsftp_users.conf
#下面一行用户名一行密码【奇数行用户名,偶数行密码】
#下面的用户名和密码是虚拟出来的,本地用户中不存在下列用户名和密码
yb1
yb1_passwd
yb2
yb2_passwd
~
- 用db_load转换工具,将文本文件(上一步所建立的文件)转化为数据库文件
#如果是最小化安装,没有db_load命令【完整安装忽略这步】,先安装命令:yum -y install db4-utils
【可以先执行下面命令,有命令忽略这步】
[root@centos76_2 vsftpd]# db_load -T -t hash -f /etc/vsftpd/vsftp_users.conf /etc/vsftpd/vsftp_users.db
- 修改虚拟用户列表文件及数据库文件访问权限。
#600权限是只有用户有读和写权限
[root@centos76_2 vsftpd]# chmod 600 /etc/vsftpd/vsftp_users.db
[root@centos76_2 vsftpd]#
[root@centos76_2 vsftpd]# ll vsftp_users.*
-rw-r--r--. 1 root root 16 May 7 05:15 vsftp_users.conf
-rw-------. 1 root root 12288 May 7 05:16 vsftp_users.db
[root@centos76_2 vsftpd]#
(2)创建虚拟用户对应的本地用户
禁止他们本地登录
设置用户主目录的访问权限
# useradd -d 是指定家目录,指定以后/home里面就看不到了
[root@centos76_2 vsftpd]# useradd -d /var/ftp/share -s /sbin/nologin vuser1
[root@centos76_2 vsftpd]# useradd -d /var/ftp/noshare -s /sbin/nologin vuser2
[root@centos76_2 vsftpd]# echo "vuser1_passwd" | passwd --stdin vuser1
Changing password for user vuser1.
passwd: all authentication tokens updated successfully.
[root@centos76_2 vsftpd]# echo "vuser2_passwd" | passwd --stdin vuser2
Changing password for user vuser2.
passwd: all authentication tokens updated successfully.
[root@centos76_2 vsftpd]#
[root@centos76_2 vsftpd]# chmod 500 /var/ftp/share #500是只有用户有写和执行权限
[root@centos76_2 vsftpd]# chmod 700 /var/ftp/noshare #700 是只有用户有 读写执行权限
[root@centos76_2 vsftpd]#
[root@centos76_2 vsftpd]# ll /var/ftp/ | grep re
drwx------. 3 vuser2 vuser2 78 May 6 21:57 noshare
dr-x------. 3 vuser1 vuser1 78 May 6 21:57 share
[root@centos76_2 vsftpd]#
(3)创建日志文件
[root@centos76_2 vsftpd]# touch /var/log/vsftpd.log
[root@centos76_2 vsftpd]# chown vuser1:vuser1 /var/log/vsftpd.log #如果有多个用户,可以不用指定用户和用户组的
(4)修改SELinux安全上下文,允许对用户主目录读写
[root@centos76_2 vsftpd]# chcon -t public_content_rw_t /var/ftp/noshare/
[root@centos76_2 vsftpd]# chcon -t public_content_r_t /var/ftp/share/
(5)selinux 开放对ftp的访问
selinux可能会阻止对其他目录的访问,所以最好放开。
查看后如果你 下列3项on的内容和我一样,可忽略,如果不是,执行后面命令即可
[root@centos76_2 vuser_conf]# getsebool -a | grep ftp
ftpd_anon_write --> on
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> on
ftpd_use_cifs --> ooff
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 --> on
[root@centos76_2 vuser_conf]# setsebool -P ftp_home_dir on 【on和1均可】
[root@centos76_2 vuser_conf]# setsebool -P ftpd_home_dir on
[root@centos76_2 vuser_conf]# setsebool -P ftpd_anon_write on
(6)建立支持虚拟用户的PAM认证文件
- 因为现在的验证方式跟之前的不同了,所以需要自己创建一个PAM模块文件,然后在主配置文件中调用该文件
[root@centos76_2 pam.d]# vim vsftpd.vu
# 新增下列2行
auth required pam_userdb.so db=/etc/vsftpd/vsftp_users
account required pam_userdb.so db=/etc/vsftpd/vsftp_users
[root@centos76_2 pam.d]#
auth
是指对用户的用户名口令进行验证。accou
t是指对用户的帐户有哪些权限哪些限制进行验证。pam_userdb.so
是/usr/lib64/security/pam_userdb.so的缩写【如果自己的机子是32位用lib】,表示该条审核将调用这个库函数进行。db
指向的文件实际上指向的/etc/vsftpd/vsftp_users.db ,但默认省略db后缀,故上述db的指向时在配置的时候不能写为vsftp_users.db
(7)修改vsftpd配置文件
- 下面为虚拟用户必须配置项
[root@centos76_2 vuser_conf]# vim /etc/vsftpd/vsftpd.conf
# 自行检查下面的服务是否一致
anonymous_enable=NO #不允许匿名访问
local_enable=YES #本地用户可以访问
chroot_list_enable=YES #使用户不能离开主目录
ascii_upload_enable=YES #允许上传
ascii_download_enable=YES #支持ASCII模式的下载功能,这个可以要可不要
pam_service_name=vsftpd.vu #千万别忘记修改,这是第(4)步的PAM认证存放文件
#手工输入以下参数和值
guest_enable=YES #开启虚拟用户的功能
#guest_username=vir #指定虚拟用户的宿主用户,如果有多个用户可以不用在这指定,而在虚拟用户文件中指定即可【下面跳目录中】
user_config_dir=/etc/vsftpd/vuser_conf #指定虚拟用户权限配置文件目录
xferlog_file=/var/log/vsftpd.log #vsftpd的服务日志保存路径,默认不存在
- 注:上面中
pam_service_name=vsftpd
如果修改以后,本地用户就不能登陆了,只能通过虚拟用户登陆,所以建议像我下面这样新增一行改为虚拟PAM认证的名称,后面想用本地用户登陆了,就把虚拟用户的PAM认真注释,另外一个取消注释即可。
- 解释
如果我们把虚拟用户PAM认证文件【上面(4)中内容】内容放这里面默认文件【/etc/pam.d/vsftpd】里面,那么其他就必须全部注释掉,否则虚拟用户无法登陆,而全部注释以后,本地用户就无法登陆了【原因见下图】
(8)创建并自定义虚拟用户权限配置文件
- 这个文件是上面(5)中【user_config_dir=/etc/vsftpd/vuser_conf】定义的文件
文件中的每条功能代码已经做出说明,注意看注释【基本上你需要要用的权限下面都能找到】
[root@centos76_2 pam.d]# mkdir /etc/vsftpd/vuser_conf
[root@centos76_2 pam.d]# cd /etc/vsftpd/vuser_conf/
[root@centos76_2 vuser_conf]# vim yb1 #创建虚拟用户配置文件【权限等】
#用户登陆后的所在目录
local_root=/var/ftp/share
#虚拟用户对应的本地用户【如果只有一个虚拟用户,下面条可以放在(5)的配置文件中
guest_username=vuser1
#允许浏览和下载【下面设为no就是关闭只可读】
anon_world_readable_only=NO
#限定传输速率为500KB/s
anon_max_rate=500000
[root@centos76_2 vuser_conf]#
[root@centos76_2 vuser_conf]# vim yb2 #创建虚拟用户配置文件【权限等】
#用户登陆后的所在目录
local_root=/var/ftp/noshare
#虚拟用户对应的本地用户【如果只有一个虚拟用户,下面条可以放在(5)的配置文件中
guest_username=vuser2
#允许浏览和下载【下面设为no就是关闭只可读】
anon_world_readable_only=NO
#允许上传
anon_upload_enable=YES
#允许创建文件夹
anon_mkdir_write_enable=YES
#允许修改和删除
anon_other_write_enable=YES
#限定传输速率为1000KB/s
anon_max_rate=1000000
[root@centos76_2 vuser_conf]#
(9)重启vsftpd服务
[root@centos76_2 vuser_conf]# systemctl restart vsftpd
登陆报错530常见原因
报错信息如下
ftp> [root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 Welcom to ccx_ftp.
Name (192.168.59.129:root): yb1
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp>
如果你不是很懂,那就好好挨个检查上面每一步的代码,确保 你上面的配置和我一致【最好都复制粘贴】,如果依然有问题,从下面排查:
1.网络是否通畅
如果网络不通,那么在使用ftp ip 端口 来进行连接FTP时,直接就连接不了,不会让你输入用户和密码,所以排除第一种情况
2.端口是否被占用
FTP汲及到的端口主要有,一个是服务监听端口(listen_port=xxx),二是数据传输用的端口(pasv_min_port=xxx,pasv_max_port=xxx)
3.权限设置
这种一般会报权限不足的提示
4.FTP用户密码过期
若以上方案都没解决,则看看用户密码是否过期了(如果是用的虚拟用户,是不存在这一问题的)
虚拟用户使用说明
- 当上述的虚拟用户配置完毕以后,虚拟用户和本地用户的使用方法是一样的,需要输入(1)步骤中的用户名和其密码进行登陆。
- 这样的好处就是不用给别人真实的本地用户和密码。
登陆测试【linux更直观】
- 上面(8)步骤中分别对这2个虚拟用户指定了宿主用户和其根目录,下面测试是否正常
- 服务端查看这2个根目录中的文件:
[root@centos76_2 vsftpd]#
[root@centos76_2 vsftpd]# ls /var/ftp/share/
error.txt put_test.txt.txt share1 share2 share3
[root@centos76_2 vsftpd]#
[root@centos76_2 vsftpd]# ls /var/ftp/noshare/
noshare4 noshare5 noshare6
[root@centos76_2 vsftpd]#
- 测试开始
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 Welcom to ccx_ftp.
Name (192.168.59.129:root): yb1 #登陆yb1
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 (192,168,59,129,92,150).
150 Here comes the directory listing.
-rw-r--r-- 1 1008 1008 0 May 07 08:05 error.txt
-rw-r--r-- 1 1008 1008 0 May 07 08:05 put_test.txt.txt
-rw-r--r-- 1 0 0 0 May 07 03:25 share1
-rw-r--r-- 1 0 0 0 May 07 03:25 share2
-rw-r--r-- 1 0 0 0 May 07 03:25 share3
226 Directory send OK.
ftp> bye
221 Goodbye.
[root@centos76_1 ~]# ftp 192.168.59.129
Connected to 192.168.59.129 (192.168.59.129).
220 Welcom to ccx_ftp.
Name (192.168.59.129:root): yb2 # 登陆yb2
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 (192,168,59,129,196,36).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare4
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare5
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare6
226 Directory send OK.
ftp>
测试权限【windows更直观】
- yb1只能进行下载
- yb2能进行下载和上传
ftp服务端配置【windows】
- windwows可以用软件部署,工具有很多,网上可以搜到,并且图形化很简单,这个不做说明,网上一搜各种软件都会有使用说明的。
- 这儿推荐个网站:
官网地址:http://seo.iis7.com/
【站长之家】
这里面工具多很,要什么都有。
关于ftp工具包,不想去刚才网站里面找的,可以下载我已经下载好的服务端和客户端,已经在里面添加了使用说明: