首页 > 系统相关 >Linux搭建FTP服务器

Linux搭建FTP服务器

时间:2022-12-19 14:08:18浏览次数:49  
标签:FTP enable ftp ## vsftpd file Linux 服务器 YES


这里写自定义目录标题

  • ​​Linux搭建FTP服务器​​
  • ​​简述​​
  • ​​一.安装服务器​​
  • ​​1.1. 安装vsftp​​
  • ​​1.2. 配置文件路径​​
  • ​​二. 配置vsftp​​
  • ​​2.1. 配置ftp用户​​
  • ​​2.2. 配置vsftp​​
  • ​​2.3. 注释掉auth防止无法登陆​​
  • ​​2.4. 启动ftp服务器​​
  • ​​2.5. 浏览器登陆​​
  • ​​三. Win配合使用​​
  • ​​四. vsftp常用配置​​
  • ​​五. 总结​​

Linux搭建FTP服务器

简述

FTP是File Transfer Protocol(文件传输协议)的简称,用于internet上的控制文件的双向传输。
FTP也是一个应用程序,基于不同的操作系统有不同的FTP应用程序,而所有这些应用程序都遵守同一种协议以传输文件。

一.安装服务器

1.1. 安装vsftp

yum install -y vsftp

1.2. 配置文件路径

配置文件

/etc/vsftp/vsftp.conf

vsftpd用户认证配置文件

/etc/pam.d/vsftpd

配置文件目录

/etc/vsftpd/

1.3. vsftp常用命令

启动ftp服务器

service vsftp start

停止ftp服务器

service vsftp stop

查看ftp服务器

service vsftp status

二. 配置vsftp

2.1. 配置ftp用户

useradd ftpuser                          # 创建ftp用户
echo ftppasswd | passwd ftpuser --stdin # 设置ftp用户的密码
usermod -s /sbin/nologin ftpuser # 不允许ftp用户登陆
usermod -d /home/ftpuser/file ftpuser # 设置ftpuser用户的访问路径
chmod 777 -R /home/ftpuser/file/ # 设置ftp用户的读写权限

2.2. 配置vsftp

# 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.
# 取消对此的注释以允许本地用户登陆
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
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
#
# Activate logging of uploads/downloads.
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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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=欢迎登陆本地的FTP服务器.
#
# 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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
allow_writeable_chroot=YES
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=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then 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

2.3. 注释掉auth防止无法登陆

[root@molongyin file]# cat /etc/pam.d/vsftpd
#%PAM-1.0
session optional pam_keyinit.so force revoke
auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
#auth required pam_shells.so # 注释掉
auth include password-auth
account include password-auth
session required pam_loginuid.so
session include password-auth

2.4. 启动ftp服务器

service vsftp start

2.5. 浏览器登陆

我们在 ​​/home/ftpuser/file​​​ 下面创建一个测试文件 ​​1.txt​​​ 文件。
接着打开浏览器: ​​​ftp://192.168.31.26​​​ 你测试的Centos服务器的地址。
![image.png](/i/ll/?i=img_convert/e0ac2155a5bf3ef15b37b344140e63ad.png#align=left&display=inline&height=255&margin=[object Object]&name=image.png&originHeight=255&originWidth=856&size=75852&status=done&style=none&width=856)
首次访问会让你输入用户(ftpuser)密码(ftppasswd),然后就可以进入看到我们刚才的创建的测试文件了。

三. Win配合使用

如果我们想要从win笔记本上传文件的话,不需要下载软件,打开控制台(cmd或者wt),输入:ftp ip 端口,就可以操作。

ftp> open 192.168.31.26 21  # 输入密码。就可以访问
ftp> put e:\test\1.txt # 上传文件
ftp> quit # 退出

其他的命令自行百度吧。

四. vsftp常用配置

参数

作用

anonymous_enable=YES

启用匿名用户登录

anon_upload_enable=YES

允许匿名用户上传

anon_mkdir_write_enable=YES

允许匿名用户创建目录,但是不能删除

anon_other_write_enable=YES

允许匿名用户创建和删除目录

local_enable=YES

启用本地用户登录

write_enable=YES

允许本地用户有写权限

local_umask=022

通过ftp上传文件的默认遮罩码

chroot_local_user=YES

禁锢所有的ftp本地用户于其家目录中

chroot_list_enable=YES

开启禁锢文件列表,需要与chroot_list_file参数一起使用

chroot_list_file=/etc/vsftpd/chroot_list

指定禁锢列表文件路径,在此文件里面的用户将被禁锢在其家目录中

allow_writeable_chroot=YES

允许被禁锢的用户家目录有写权限

xferlog_enable=YES

是否启用传输日志,记录ftp传输过程

xferlog_std_format=YES

传输日志是否使用标准格式

xferlog_file=/var/log/xferlog

指定传输日志存储的位置

chown_uploads=YES

是否启用改变上传文件属主的功能

chown_username=whoever

指定要将上传的文件的属主改为哪个用户,此用户必须在系统中存在

pam_service_name=vsftpd

指定vsftpd使用/etc/pam.d下的,哪个pam配置文件进行用户认证

userlist_enable=YES

是否启用控制用户登录的列表文件:默认为/etc/vsftpd/user_list文件

userlist_deny=YES

是否拒绝userlist指定的列表文件中存在的用户登录ftp

max_clients=#

最大并发连接数

max_per_ip=#

每个IP可同时发起的并发请求数

anon_max_rate

匿名用户的最大传输速率,单位是“字节/秒”

local_max_rate

本地用户的最大传输速率,单位是“字节/秒”

dirmessage_enable=YES

启用某目录下的.message描述信息,假定有一个目录为/upload,在其下创建一个文件名为.message,在文件内写入一些描述信息,则当用户切换至/upload目录下时会自动显示.message文件中的内容

message_file

设置访问一个目录时获得的目录信息文件的文件名,默认是.message

idle_session_timeout=600

设置默认的断开不活跃session的时间

data_connection_timeout=120

设置数据传输超时时间

ftpd_banner=“Welcome to chenlf FTP service.”

定制欢迎信息,登录ftp时自动显示

五. 总结

配合ftp和ssh我们其实可以抛弃现在的xshell和sftp等一些软件。简单又方便!


标签:FTP,enable,ftp,##,vsftpd,file,Linux,服务器,YES
From: https://blog.51cto.com/luckyqilin/5952239

相关文章

  • Linux的一些指令
    ls查看当前目录tail-flog的位置查看日志(展示最后几行,即更新了会打印出来)具体可查看https://blog.csdn.net/weixin_42230607/article/details/116578465cat打开文......
  • linux回炉第三天
    /etc/passwd/etc/shadow/etc/group/etc/gshadowchage-lwanguseradduseradd-Guseradd-guseradd-uuseradd-duseradd-suseradd-Museradd-cuseradd-ruseradd-D#......
  • kaliLinux使用——共享文件夹挂载
    1、创建共享目录:mkdir-p/mnt/hgfs/sharekali2、挂载:/usr/bin/vmhgfs-fuse.host:/sharekali/mnt/hgfs/sharekali-osubtype=vmhgfs-fuse,allow_other3、开机自动挂载......
  • 游戏服务器的配置如何选择
    1.服务器的CPU大型的游戏要接受大量的访问请求,CPU的快速吞吐量、稳定性、长时间运行都有着严格的要求,因而服务器CPU是衡量服务器性能的首要指标。之前提到根据游戏的类......
  • 【服务器数据恢复】NTFS文件系统服务器raid5数据恢复案例
    服务器数据恢复环境:一台使用NTFS文件系统的服务器;7块硬盘组成了一组raid5磁盘阵列。服务器故障&初检:raid5磁盘阵列磁盘故障离线导致服务器瘫痪。用户在处理掉线磁盘时只......
  • 查看Linux服务器日志
    查看关键字前后5行的日志查看关键字前后5行的日志cat日志文件|grep-C5'关键字'查看带有行号的关键字前后5行日志cat-n日志文件|grep-C5'关键字'......
  • LInux三剑客之正则表达式
    正则表达式注意事项:正则的符号,都是英文;推荐使用grep/egrep,默认设置了别名,自动加上颜色;http://nbre.oldboylinux.cn分析正则与正则匹配到的内容; 符号概述:正则表达......
  • Linux四剑客与正则之sed命令
    sed:常用来取行,过滤,替换修改文件内容;向后引用;格式:sed选项'条件动作/找谁干啥'文件;取出文件第3行sed-n'3p'/etc/passwd//p就是输出,-n,取消默认输出如何运行:sed命令运行......
  • Qt音视频开发06-海康sdk内核linux客户端
    一、前言海康sdk的示例在官方是提供了的,但是无论UI还是交互简直是宇宙无敌的垃圾,猜测应该是初学者编写的,估计练手用的,所以老早就想把这个linux支持集成到自己的示例中,既然......
  • Linux入门到精通
    时间同步chrony1、ntp服务器搭建yum-yinstallchronyvi/etc/chrony.conf....#server用户客户端指向,上层NTP服务器server0.centos.pool.ntp.orgiburstserver......