文章目录
- linux系统,ftp客户端配置
- - - - - - - - FTP客户端配置- - - - - - 开始
- ftp客户端配置--linux
- - - - - - - - FTP客户端配置- - - - - - 结束
- linux系统,ftp服务端vsftpd配置
- - - - - - - - FTP服务端配置- - - - - - 开始
- ftp服务端配置--linux系统(使用shell脚本)
- ftp服务端配置–linux系统(操作配置文件)
- - - - - - - - FTP服务端配置- - - - - - - 结束
- **linux系统,ftp客户端使用示例**
- - - - - - - - FTP客户端使用实例- - - - - - 开始
- linux命令行使用【推荐】
- ftp使用实例
- linux浏览器使用【不推荐】
- - - - - - - - FTP客户端使用实例- - - - - - 结束
linux系统,ftp客户端配置
- - - - - - - FTP客户端配置- - - - - - 开始
ftp客户端配置–linux
linux上使用,仅需要 安装ftp包:yum install -y ftp
客户端访问的前提是,ftp服务端需要配置完毕,配置完毕以后 客户端可以直接访问的。
注:ftp服务端只需要把vsftpd服务启动,客户端就可以访问了哦。ftp配置方法见最下面“ftp服务端配置–linux”
ftp客户端安装包
链接:https://pan.baidu.com/s/1yDal6NTDcPOpNmWA8IebOA?pwd=jar4
提取码:jar4
ftp客户端安装脚本
- 【可以通过以下两种方式获取ftp-0.17-54.el6.x86_64.rpm安装脚本】
链接:https://pan.baidu.com/s/1EW4ZEwBcT34p2rOYzvEeiQ?pwd=wvwk
提取码:wvwk
#!/bin/bash
#安装软件
packageName="ftp"
package="ftp-0.17-54.el6.x86_64.rpm"
pName=$(rpm -qa | grep "${packageName}")
if [ $? -eq 0 ]
then
echo "软件包"${packageName}"已经安装。"
else
echo "软件包"${packageName}"没有安装"
echo "开始安装"${package}"……"
rpm -ivh ${package}
if test $? -eq 0
then
echo "安装"${package}"完成。"
else
echo "安装"${package}"失败。"
fi
fi
sleep 3
#开机自启动
chkconfig iptables off
reboot
- - - - - - - FTP客户端配置- - - - - - 结束
linux系统,ftp服务端vsftpd配置
- - - - - - - FTP服务端配置- - - - - - 开始
ftp服务端配置可以使用两种方式:使用以下脚本,或者自行修改配置文件进行配置【脚本配置其实是对,自行操作配置进行了整合】
ftp服务端配置–linux系统(使用shell脚本)
ftp服务端vsftpd安装包
- vsftpd-3.0.2-25.el7.x86_64.rpm安装包
链接:https://pan.baidu.com/s/1n-LEprWyYybtugtYZxI16w?pwd=vqff
提取码:vqff
- vsftpd-2.2.2-11.el6_4.1.x86_64.rpm安装包
链接:https://pan.baidu.com/s/1Up6FkXAM4GIe8_rtvqgzZg?pwd=4rnt
提取码:4rnt
ftp服务端vsftpd配置文件–vsftpd.conf
- 【可以通过以下两种方式获取vsftpd的配置文件】
链接:https://pan.baidu.com/s/1ZeRPyUIqFgAbbIyEg-W93g?pwd=gaon
提取码:gaon
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
allow_writeable_chroot=YES
#write_enable=YES
ftp服务端selinux配置文件–config
- 【可以通过以下两种方式获取selinux的配置文件】
链接:https://pan.baidu.com/s/120-mKwZbNTMaZrWOAmdrAQ?pwd=bz92
提取码:bz92
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
注意:把vsftpd安装包,vsftpd的配置文件vsdtpd.conf,seliunx的配置文件放在同一个文件夹下,再执行以下vsftpd安装脚本
ftp服务端vsftpd安装脚本
- 【可以通过以下两种方式获取vsftpd-3.0.2-25.el7.x86_64.rpm安装脚本】
链接:https://pan.baidu.com/s/1PlImt7Ul603BnoqZftfNiw?pwd=9yoz
提取码:9yoz
#!/bin/bash
echo "此脚本实现通过用户名,密码登录,ftp协议上传下载文件,用户名ftp 密码123456且该用户只能在访问指定目录,互联网端目录/minedata/TraRoad/waiwang/rticdataredis,此目录需要根据用户的需求去改动"
echo "安装即将开始^*^"
sleep 3
#安装软件
packageName="vsftpd"
package="vsftpd-3.0.2-25.el7.x86_64.rpm"
path="/minedata/TraRoad/waiwang/rticdataredis"
pName=$(rpm -qa | grep "${packageName}")
if [ $? -eq 0 ]
then
echo "软件包"${packageName}"已经安装。"
else
echo "软件包"${packageName}"没有安装"
echo "开始安装"${package}"……"
rpm -ivh ${package}
if test $? -eq 0
then
echo "安装"${package}"完成。"
else
echo "安装"${package}"失败。"
fi
fi
sleep 3
#创建ftp目录 /var/ftp/pub
mkdir -p "${path}"
chmod 4777 "${path}" #否则客户端用户无法创建文件
#创建用户名 ftp 密码 123456
name="ftp"
pass="123456"
echo "you are setting username : ${name}"
echo "you are setting password : $pass for ${name}"
sleep 3
#判断用户是否存在 存在就修改目录 密码,不存在就创建
if id -u $name >/dev/null 2>&1; then
echo "user exists"
usermod -d $path $name
echo $pass | passwd $name --stdin &>/dev/null
if [ $? -eq 0 ];then
echo "${name}'s password is set successfully"
else
echo "${name}'s password is set failly!!!"
fi
else
echo "user does not exist"
useradd -d $path -s /sbin/nologin $name
if [ $? -eq 0 ];then
echo "user ${name} is created successfully!!!"
echo $pass | passwd $name --stdin &>/dev/null
if [ $? -eq 0 ];then
echo "${name}'s password is set successfully"
else
echo "${name}'s password is set failly!!!"
fi
else
echo "user ${name} is created failly!!!"
exit 1
fi
fi
sleep 3
#覆盖配置文件
mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.BK
cp vsftpd.conf /etc/vsftpd/vsftpd.conf
chmod 600 /etc/vsftpd/vsftpd.conf
mv /etc/selinux/config /etc/selinux/config.BK
cp config /etc/selinux/config
#开机自启动
systemctl disable firewalld.service
chkconfig --add vsfptd
chkconfig vsftpd on
setenforce 0
systemctl stop firewalld
systemctl start vsfptd
systemctl restart vsftpd
echo "/sbin/nologin">>/etc/shells
echo "成功啦,即将重启....."
sleep 5
#reboot
ftp服务端配置–linux系统(操作配置文件)
关闭防火墙
[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源
安装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,和上面一个配套使用
上面基本是常用的配置了,测试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=022
anon_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段访问此FTP
chroot_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/vsftpd
userlist_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/默认没有这一项
#使用本地时间而不是GMT
nopriv_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无法正常使用。
- 检查 vsftpd服务是不是正常开启
- 检查防火墙是否关闭【如果防火墙有放开策略了,关不关无所谓】
- 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)常用的全局配置(对所有用户都生效)
全局配置–上传功能配置
- 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目录底下删除文件
(2)本地用户访问限制
- 本地用户意思是说:下面功能仅对 服务端上的用户生效,不是服务端上的用户名,一律阻止【不允许访问】
- 查看本地用户,目录:
/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访问)。
如果你是能够链接到FTP 但是看不到文件 上传和下载都没有办法做出操作,再做下面操作2、修改权限
执行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】
登陆进来以后看到是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
[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,而是说列表中的用户不受功能限制,比如下面限制了本地用户不能翻目录,但列表中的用户依然是可以翻目录的【其他用户只能登陆到家目录不能切换其他目录】,就是这样,之前我以为是这个只允许列表中用户登陆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
(3)游客用户【虚拟用户】
说明
在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
是指对用户的用户名口令进行验证。accout
是指对用户的帐户有哪些权限哪些限制进行验证。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只能进行下载
- - - - - - - FTP服务端配置- - - - - - - 结束
linux系统,ftp客户端使用示例
- - - - - - - FTP客户端使用实例- - - - - - 开始
linux命令行使用【推荐】
最简单的登陆方式:ftp ip
回车输入用户名和密码即可 也可以加入参数使用:ftp -参数 ip
【参数介绍见下面】
[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:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
linux命令行_参数说明
- 参数使用:
ftp [-v] [-n] [-i] [-d] [-g] [-s:filename] [-a] [-w:windowsize] [computer]
- 参数说明
-v 禁止显示远程服务器响应。
-n 禁止自动登录到初始连接。
-I 多个文件传送时关闭交互提示。
-d 启用调试、显示在客户端和服务器之间传递的所有 ftp 命令。
-g 禁用文件名组,它允许在本地文件和路径名中使用通配符字符(* 和 ?)。(请参阅联机“命令参考”中的 glob 命令。)
-s: filename指定包含 ftp 命令的文本文件;当 ftp 启动后,这些命令将自动运行。该参数中不允许有空格。使用该开关而不是重定向 (>)。
-a 在捆绑数据连接时使用任何本地接口。
-w:windowsize 替代默认大小为 4096 的传送缓冲区。
Computer 指定要连接到远程计算机的计算机名或 IP 地址。如果指定,计算机必须是行的最后一个参数。
linux命令行_命令说明
- 命令使用 登陆上ftp服务器以后直接输入命令执行相关功能
全部命令说明
- 登陆后输入
?
可以显示全部命令,输入? 命令
可以查看介绍【英文看不懂?下面有中网介绍】。
- 按字母顺序总结的【基本这就是全部了】
![cmd]:
从ftp子系统退出到系统外壳【在本地机中执行交互shell,并不是所有命令都支持,常用于 !ls查看本地文件】
$ macro-ame[args]
: 执行宏定义macro-name。
account[password]
: 提供登录远程系统成功后访问系统资源所需的补充口令。
append local-file[remote-file]
:将本地文件追加到远程系统主机,若未指定远程系统文件名,则使用本地文件名。
ascii
:使用ascii类型传输方式。
lcd
: 更换本地目录,若无参数,将显示当前目录
bell
:每个命令执行完毕后计算机响铃一次。
bin
:使用二进制文件传输方式。
bye
: 结束与远程计算机的 FTP 会话并退出 ftp
case
:在使用mget时,将远程主机文件名中的大写转为小写字母。
cd remote-dir
:进入远程主机目录。
cdup
:进入远程主机目录的父目录。
chmod mode file-name
:将远程主机文件file-name的存取方式设置为mode,如:chmod 777 a。
close
:中断与远程服务器的ftp会话(与open对应)。
cr
:使用asscii方式传输文件时,将回车换行转换为回行。
delete remote-file
:删除远程主机文件。
debug[debug-value]
:设置调试方式, 显示发送至远程主机的每条命令,如:deb up 3,若设为0,表示取消debug。
dir[remote-dir][local-file]
:显示远程主机目录,并将结果存入本地文件
disconnection
:同close。
form format
:将文件传输方式设置为format,缺省为file方式。
get remote-file[local-file]
: 将远程主机的文件remote-file传至本地硬盘的local-file。
glob
:设置mdelete,mget,mput的文件名扩展,缺省时不扩展文件名,同命令行的-g参数。
hash
:每传输1024字节,显示一个hash符号(#)。
help[cmd]
:显示ftp内部命令cmd的帮助信息,如:help get。
idle[seconds]
:将远程服务器的休眠计时器设为[seconds]秒。
image
:设置二进制传输方式(同binary)。
lcd[dir]
:将本地工作目录切换至dir。
ls[remote-dir][local-file]
:显示远程目录remote-dir, 并存入本地文件local-file。
macdef macro-name
:定义一个宏,遇到macdef下的空行时,宏定义结束。
mdelete[remote-file]
:删除远程主机文件。
mdir remote-files local-file
:与dir类似,但可指定多个远程文件,如 :mdir 、o、、zipoutfile。
mget remote-files
:传输多个远程文件。
mkdir dir-name
:在远程主机中建一目录。
mls remote-file local-file
:同nlist,但可指定多个文件名。
mode[modename]
:将文件传输方式设置为modename, 缺省为stream方式。
modtime file-name
:显示远程主机文件的最后修改时间。
mput local-file
:将多个文件传输至远程主机。
newer file-name
: 如果远程机中file-name的修改时间比本地硬盘同名文件的时间更近,则重传该文件。
nlist[remote-dir][local-file]
:显示远程主机目录的文件清单,并存入本地硬盘的local-file。
nmap[inpattern outpattern]
:设置文件名映射机制, 使得文件传输时,文件中的某些字符相互转换, 如:nmap $1、$2、$3[$1,$2]、[$2,$3],则传输文件a1、a2、a3时,文件名变为a1,a2。 该命令特别适用于远程主机为非UNIX机的情况。
ntrans[inchars[outchars>
:设置文件名字符的翻译机制,如ntrans1R,则文件名LLL将变为RRR。
open host[port]
:建立指定ftp服务器连接,可指定连接端口。
passive
:进入被动传输方式。
prompt
:设置多个文件传输时的交互提示。
proxy ftp-cmd
:在次要控制连接中,执行一条ftp命令, 该命令允许连接两个ftp服务器,以在两个服务器间传输文件。第一条ftp命令必须为open,以首先建立两个服务器间的连接。
put local-file[remote-file]
:将本地文件local-file传送至远程主机。
pwd
:显示远程主机的当前工作目录。
quit
:同bye,退出ftp会话。
quote arg1,arg2、、、
:将参数逐字发至远程ftp服务器,如:quote syst、
recv remote-file[local-file]
:同get。
reget remote-file[local-file]
:类似于get, 但若local-file存在,则从上次传输中断处续传。
rhelp[cmd-name]
:请求获得远程主机的帮助。
rstatus[file-name]
:若未指定文件名,则显示远程主机的状态, 否则显示文件状态。
rename[from][to]
:更改远程主机文件名。
reset
:清除回答队列。
restart marker
:从指定的标志marker处,重新开始get或put,如:restart 130。
rmdir dir-name
:删除远程主机目录。
runique
:设置文件名只一性存储,若文件存在,则在原文件后加后缀、1, 、2等。
send local-file[remote-file]
:同put。
sendport
:设置PORT命令的使用。
site arg1,arg2、、、
:将参数作为SITE命令逐字发送至远程ftp主机。
size file-name
:显示远程主机文件大小,如:site idle 7200。
status
:显示当前ftp状态。
struct[struct-name]
:将文件传输结构设置为struct-name, 缺省时使用stream结构。
sunique
:将远程主机文件名存储设置为只一(与runique对应)。
system
:显示远程主机的操作系统类型。
tenex
:将文件传输类型设置为TENEX机的所需的类型。
tick
:设置传输时的字节计数器。
trace
:设置包跟踪。
type[type-name]
:设置文件传输类型为type-name,缺省为ascii,如:type binary,设置二进制传输方式。
umask[newmask]
:将远程服务器的缺省umask设置为newmask,如:umask 3
user user-name[password][account]
:向远程主机表明自己的身份,需要口令时,必须输入口令,如:user anonymous my@email。
verbose
:同命令行的-v参数,即设置详尽报告方式,ftp 服务器的所有响 应都将显示给用户,缺省为on、
? [cmd]
:同help、
如果linux是图形化安装,也可以打开浏览器,像Windows一样在浏览器访问或下载文件的
常用命令说明
常用的无法就是登陆上去,切换远程和本地目录,上传、下载、删除和新增文件罢了。
![cmd]:
从ftp子系统退出到系统外壳【在本地机中执行交互shell,并不是所有命令都支持,常用于 !ls和!pwd查看本地文件和路径】
? [cmd]:
显示ftp说明,跟help一样
cd
: 更换远程目录
lcd
: 更换本地目录,若无参数,将显示当前目录
open
: 与指定的ftp服务器连接 open computer [port]【这个可以指定端口】
close
:结束与远程服务器的 FTP 会话并返回命令解释程序
bye
: 结束与远程计算机的 FTP 会话并退出 ftp
dir
: 结束与远程计算机的 FTP 会话并退出 ftp
get
和 recv
:下载文件,使用当前文件转换类型将远程文件复制到本地计算机 get remote-file [local-file]
put
和 send
: 上传文件:send local-file [remote-file]
delete remote-file
:删除远程主机文件。
mget remote-files
:传输多个远程文件。
mkdir dir-name
:在远程主机中建一目录。
modtime file-name
:显示远程主机文件的最后修改时间。
mput local-file
:将多个文件传输至远程主机。
pwd
:显示远程主机的当前工作目录。
rename[from][to]
:更改远程主机文件名。
ftp使用实例
如果不熟悉上面的使用方法,可以把上面常用命令截图钉在屏幕上,边看命令变使用,效率更高哦。
直接登陆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: #输入密码
230 Login successful. #提示230登陆成功
Remote system type is UNIX.
Using binary mode to transfer files.
进入ftp后登陆【常用于指定端口】
说明见代码后面
[root@centos76_1 ~]# ftp # 输入ftp回车
ftp> open 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: #输入密码
230 Login successful. #登陆成功
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> close # 断开链接
221 Goodbye.
ftp> open 192.168.59.129 21 #指定端口21
Connected to 192.168.59.129 (192.168.59.129).
220 Welcom to ccx_ftp.
Name (192.168.59.129:root): yb2 # 输入用户名
331 Please specify the password.
Password:#输入密码
230 Login successful.
Remote system type is UNIX. # 登陆成功
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> bye # 退出ftp
221 Goodbye.
[root@centos76_1 ~]#
进入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:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put ip_tool.sh # 上传文件报错如下
local: ip_tool.sh remote: ip_tool.sh
227 Entering Passive Mode (192,168,59,129,88,57).
553 Could not create file.
ftp>
ftp> get share1 # 下载文件报错如下
local: share1 remote: share1
227 Entering Passive Mode (192,168,59,129,187,85).
150 Opening BINARY mode data connection for share1 (0 bytes).
226 Transfer complete.
ftp>
ftp> delete share1 # 删除文件报错如下
550 Delete operation failed.
- 各个功能代码上面有介绍,下面记得看代码后面说明
[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 #这是一个满权限用户
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,140,86).
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
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> !pwd# 查看本地路径
/root
ftp> !ls #查看本地文件
anaconda-ks.cfg ccx initial-setup-ks.cfg ip_tool.sh share1 test1 公共 模板 视频 图片 文档 下载 音乐 桌面
ftp> lcd /var/ftp/ #切换本地目录
Local directory now /var/ftp
ftp> !ls #查看查看本地文件
file1 file2 file3 pub test4 test5 test6
ftp> ls # 查看远程文件
227 Entering Passive Mode (192,168,59,129,197,117).
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
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> cd /var/ftp # 切换远程路径
550 Failed to change directory. # 报错了,没有权限,配置的时候限制在家目录了
ftp> !ls
file1 file2 file3 pub test4 test5 test6
ftp> put test4 # 上传本地文件到远程
local: test4 remote: test4
227 Entering Passive Mode (192,168,59,129,211,170).
150 Ok to send data. #上传成功
226 Transfer complete.
ftp> put file1 #上传文件夹,报错,只能上传文件
local: file1 remote: file1
file1: not a plain file.
ftp> ls # 上传的test4文件已经有了
227 Entering Passive Mode (192,168,59,129,247,222).
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 1009 1009 0 May 08 08:23 test4
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> delete file1_new #删除一个文件夹,报错,为了安全,是不允许删除文件夹的
550 Delete operation failed.
ftp> delete test4 #删除test4这个文件
250 Delete operation successful.
ftp> ls #已经被删除
227 Entering Passive Mode (192,168,59,129,48,66).
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
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp>
ftp> get noshare4 #下载远程文件到本地
local: noshare4 remote: noshare4
227 Entering Passive Mode (192,168,59,129,186,157).
150 Opening BINARY mode data connection for noshare4 (0 bytes).
226 Transfer complete.
ftp> !ls # 本地文件中已经有这个文件了
file1 file2 file3 noshare4 pub test4 test5 test6
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): 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,111,76).
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
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> mkdir file1 #创建一个文件夹file1
257 "/file1" created
ftp> ls #已经创建
227 Entering Passive Mode (192,168,59,129,72,222).
150 Here comes the directory listing.
drwxr-xr-x 2 1009 1009 6 May 08 08:54 file1
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare4
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare5
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> rename file1 file1_new #重命名文件夹
350 Ready for RNTO.
250 Rename successful.
ftp> ls #已经重命名
227 Entering Passive Mode (192,168,59,129,213,198).
150 Here comes the directory listing.
drwxr-xr-x 2 1009 1009 6 May 08 08:54 file1_new
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare4
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare5
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> cd file1_new #进入刚创建的文件夹
250 Directory successfully changed.
ftp> ls #里面没内容
227 Entering Passive Mode (192,168,59,129,107,143).
150 Here comes the directory listing.
226 Directory send OK.
ftp> cd ..# 返回上一级
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,59,129,88,133).
150 Here comes the directory listing.
drwxr-xr-x 2 1009 1009 6 May 08 08:54 file1_new
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare4
-rw-r--r-- 1 0 0 0 May 07 03:25 noshare5
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> lcd /var/ftp #切换本地目录
Local directory now /var/ftp
ftp> !ls #本地文件
file1 file2 file3 noshare4 pub test4 test5 test6
ftp> mput test4 test5 test6 #上传多个文件
mput test4? y # 输入y确定
227 Entering Passive Mode (192,168,59,129,42,244).
150 Ok to send data.
226 Transfer complete.
mput test5? y# 输入y确定
227 Entering Passive Mode (192,168,59,129,89,31).
150 Ok to send data.
226 Transfer complete.
mput test6? y# 输入y确定
227 Entering Passive Mode (192,168,59,129,45,21).
150 Ok to send data.
226 Transfer complete.
ftp> ls # 已经上传
227 Entering Passive Mode (192,168,59,129,187,200).
150 Here comes the directory listing.
drwxr-xr-x 2 1009 1009 6 May 08 08:54 file1_new
-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 1009 1009 0 May 08 08:57 test4
-rw-r--r-- 1 1009 1009 0 May 08 08:57 test5
-rw-r--r-- 1 1009 1009 0 May 08 08:57 test6
drwxr-xr-x 2 1009 1009 6 May 08 03:09 新建文件夹
226 Directory send OK.
ftp> get noshare4 noshare5 # 下载多个文件
local: noshare5 remote: noshare4
227 Entering Passive Mode (192,168,59,129,188,214).
150 Opening BINARY mode data connection for noshare4 (0 bytes).
226 Transfer complete.
ftp> !ls # 已经被下载
file1 file2 file3 noshare4 noshare5 pub test4 test5 test6
ftp>
ftp> modtime test4 #查看文件最后修改时间
test4 05/08/2021 08:57:25 GMT
ftp> 221 Goodbye.
linux浏览器使用【不推荐】
打开浏览器
浏览器中访问ftp
- - - - - - - FTP客户端使用实例- - - - - - 结束
参考链接:
1、https://blog.csdn.net/cuichongxin/article/details/116519184
2、https://blog.csdn.net/cuichongxin/article/details/101981644