FTP环境搭建及使用实例–linux系统(使用shell脚本或者使用配置文件)

本文档详细介绍了如何在Linux系统上配置FTP客户端和服务端,包括客户端的安装、服务端的vsftpd服务配置,以及使用shell脚本和配置文件进行设置。服务端配置涉及关闭防火墙、selinux,以及安装、配置vsftpd服务,包括上传、下载、删除功能的全局和本地用户限制。此外,还涵盖了虚拟用户、多用户登陆、端口修改等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章目录

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值