Linux系统(Ubuntu)配置ftp服务器

1 篇文章 0 订阅
1 篇文章 0 订阅

1.ftp目录和用户创建

创建ftp服务的目录和Ubuntu系统用户

mkdir /home/ftp
chmod -R 777 /home/ftp
# 更改一下权限,不然没法进行写
# 后面的命令需要权限的话,命令前加sudo
sudo useradd -d /home/ftpfile  -s /bin/bash ftpuser
sudo passwd ftpuser
# 输入密码并确认

扩展:

useradd命令介绍:

useradd [-d home] [-s shell] [-c comment] [-m [-k template]] [-f inactive] [-e expire ] [-p passwd] [-r] name

最后一个为用户名,-d后面指定家目录

主要参数
-c:加上备注文字,备注文字保存在passwd的备注栏中。 
-d:指定用户登入时的启始目录。***********
-D:变更预设值。
-e:指定账号的有效期限,缺省表示永久有效。
-f:指定在密码过期后多少天即关闭该账号。
-g:指定用户所属的群组。
-G:指定用户所属的附加群组。
-m:自动建立用户的登入目录。
-M:不要自动建立用户的登入目录。
-n:取消建立以用户名称为名的群组。
-r:建立系统账号。
-s:指定用户登入后所使用的shell。
-u:指定用户ID号。

------------如果中途出错需要删除用户的话------------

删除用户:userdel name

2.安装 vsftpd服务器

apt-get update

apt install vsftpd

3.ftp配置与测试

vi /etc/vsftpd.conf修改配置文件,大致如下:

# Example config file /etc/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.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
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.
listen_ipv6=YES
#
# Allow  anonymous FTP? (Disabled by default).
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 # 是否允许上传文件,不开启会报 550 permission denied  
#
# 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 # FTP上本地的文件权限,默认是077  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 # 匿名上传允许,默认是NO  
#
# 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 # 进入文件夹允许  
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES # ftp 日志记录允许  
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES # 启用20号端口作为数据传送的端口  
#
# 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/vsftpd.log
#
# 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.
# 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 restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES  # 用于指定用户列表文件中的用户是否允许切换到上级目录。默认值为NO。  
#
# 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)
chroot_local_user=YES
chroot_list_enable=YES # 设置是否启用chroot_list_file配置项指定的用户列表文件。默认值为NO。  
# user_sub_token=$USER 最初加上这句使我安装不成功
local_root=/home/ftp # 设置一个本地用户登录后进入到的目录,可以定义其他目录,与刚才用户创建的目录无关,但最好放这里
# (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
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
# !!!!!!!!!!!****************************!!!!!!!! 
pam_service_name=vsftpd
# !!!!!!!!!!!****************************!!!!!!!! 一定要把上句改好,
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
utf8_filesystem=YES

然后编辑/etc/vsftpd/chroot_list文件,将ftpuser的帐户名添加进去,保存退出。

vi /etc/vsftpd/chroot_list
# 将ftpuser加进去  多个user换行添加
ftpuser

重启并查看状态

service vsftpd restart

service vsftpd status

在这里插入图片描述
扩展:

# 卸载vsftpd
sudo apt-get remove --purge vsftpd 
#(--purge 选项表示彻底删除改软件和相关文件)

#开启、停止、重启vsftpd服务的命令:
service vsftpd start  
service vsftpd stop
service vsftpd restart
有关ftp端口。

ftp服务有两个端口,默认情况下,一个是20端口,另一个是21端口。21端口用于连接,20端口用于数据传输。
进行ftp文件传输,客户端首先连接到ftp服务器的21端口,进行用户的认证,认证成功后,要传输文件时,ftp服务器会开一个端口20来进行传输数据文件。
--------------------------------------------------.

命令行输入ifconfig可以查看该远程IP

4.测试与使用

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Linux系统配置FTP服务器,你可以按照以下步骤进行操作: 1. 安装FTP服务器软件:常用的FTP服务器软件有vsftpd、ProFTPD等。例如,如果你使用的是Debian或Ubuntu系统,可以通过以下命令安装vsftpd: ``` sudo apt-get install vsftpd ``` 2. 配置FTP服务器:编辑FTP服务器配置文件以进行必要的设置。对于vsftpd,配置文件位于`/etc/vsftpd.conf`。你可以使用文本编辑器打开该文件,例如: ``` sudo vim /etc/vsftpd.conf ``` 3. 根据需要进行配置:以下是一些常见的配置选项: - `anonymous_enable=YES`:启用匿名访问(可选)。 - `local_enable=YES`:允许本地用户访问FTP服务器。 - `write_enable=YES`:允许用户上传文件到服务器。 - `chroot_local_user=YES`:限制本地用户的访问范围为其主目录。 - `local_umask=022`:设置默认的文件权限为022。 - `pasv_min_port=xxxx`和`pasv_max_port=yyyy`:指定被动模式下使用的端口范围(可选)。 根据你的需求修改这些选项并保存文件。 4. 重新启动FTP服务器:保存配置文件后,重新启动FTP服务器以使更改生效。使用以下命令重启vsftpd服务: ``` sudo systemctl restart vsftpd ``` 5. 配置防火墙规则:如果你的系统上启用了防火墙,确保允许FTP流量通过。例如,如果你使用的是iptables防火墙,可以使用以下命令打开FTP端口(默认为21): ``` sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT ``` 以上步骤完成后,你的Linux系统上的FTP服务器应该已经配置好了。你可以使用FTP客户端软件连接到服务器并进行文件传输。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值