种地 发表于 2025-3-7 19:17:14

Linux下搭建和简朴配置FTP服务器

一、前言

网络安全实验五中必要搭建FTP服务器举行实验,在踩了一些坑之后,记录下搭建和配置过程,希望其他人可以少走弯路。
本文中Linux下安装和配置FTP在VMware中Ubuntu 16下举行,对于CentOS等其他Linux系统不实用,其他系统的安装必要参照其他文章。
同时注意权限题目,有的命令必要sudo [原命令]才可实行,因此这里根本上都用了sudo。
下面是正文
二、根本安装

1.安装ftp服务器

分别实行下列命令
sudo apt-get update
sudo apt-get install vsftpd
#这里遇到了问题1,解决方案在最下面。
之后可以利用命令vsftpd --version 检测是否安装已经安装后的版本。
2.配置ftp服务器

(1)配置文件修改之前先备份,系列命令举行备份。

sudo cp /etc/vsftpd.conf /etc/vsftpd_bk.conf
(2)修改配置文件

可以利用vim,也可以利用gedit进入修改,本人感觉gedit操作相对简朴,因此这里利用的gedit.(下面命令2选1)
利用sudo vim /etc/vsftpd.conf大概 sudo gedit /etc/vsftpd.conf
(3)配置文件内容

我这里的配置文件vsftpd.conf中内容如下(对于更深入的要求,可在之后修改配置文件),此处只配置简朴的情形。
listen=NO
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

# 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

# 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
# inyourlocaltimezone.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
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES

# 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 fully customise the login banner string:
ftpd_banner=Welcome to FTP service.


# 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
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list

# 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
pam_service_name=ftp

# 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
注意Ctrl+s生存。
对于终端中的警告暂时可以忽视(一般题目不大)。
三、添加用户

这里以添加用户t1为例,其他用户名同理可以添加。
1.先在/home下创建一个用户名目录

sudo mkdir /home/t1
2.接着绑定用户登录目录和shell

命令中-d 背面指定用户登入时的目录,-s指定用户登入后利用的shell
sudo useradd -d /home/t1 -s /bin/bash t1
3.添加用户t1的暗码

sudo passwd t1
之后暗码本身设置
4.设置/home/t1的拥有者为t1

sudo chown t1:t1 /home/t1
5.添加用户到/etc/vsftpd.user_list中

在下面命令打开的文件中添加一行,内容为t1(即你新建的用户的用户名),生存后退出。
sudo gedit /etc/vsftpd.user_list
文件中内容如下图
https://i-blog.csdnimg.cn/img_convert/9a77dbb98f7925feff4ac677a0125aea.png
6.添加用户到/etc/vsftpd.chroot_list中,新增行内容也为t1,与上一步操作雷同。

sudo gedit /etc/vsftpd.chroot_list
末了尝试重启服务
systemctl restart vsftpd
根本配置完成
四、测试

1.Ubuntu本地测试ftp localhost


https://i-blog.csdnimg.cn/img_convert/a5bef3a2cab8ce4b85bae53d75003d07.png
2.Windows下测试:

(1)cmd中: ftp IP所在


https://i-blog.csdnimg.cn/img_convert/12364ab9b012e945063ad311de60dff1.png
(2)所在栏

也可以在所在栏ftp:IP所在或ftp://IP所在/举行检察。

https://i-blog.csdnimg.cn/img_convert/f24cc5751e0736b00ad5850545260858.png
输入正确的用户名和暗码后出现

https://i-blog.csdnimg.cn/img_convert/3dcd76e42e29e0eea0b82e77a5dfd0f4.png
文件夹为空,由于我们还没有创建文件。
3.Ubuntu新建文件后测试:

在Ubuntu中新建一个文件
cd /home/t1
sudo gedit test.txt
输入下列内容后退出

https://i-blog.csdnimg.cn/img_convert/23a01dd1f338bfa78b639c458eb3b5b3.png
然后在windows下检察

https://i-blog.csdnimg.cn/img_convert/a5e29c4760b3aad74b08cb652e341c4b.png
打开txt得到

https://i-blog.csdnimg.cn/img_convert/64fd3541a0111924ab5c782bcef8cc87.png
乐成搭建了简朴的FTP服务器
五、遇到的题目

1.sudo apt-get update之后的命令出现下列题目。

E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
E: 无法获取 dpkg 前端锁 (/var/lib/dpkg/lock-frontend),是否有其他进程正占用它?
解决:
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
-frontend
之后假如:
E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
则:
sudo rm /var/lib/dpkg/lock
团体过程如下,乐成解决:
https://i-blog.csdnimg.cn/img_convert/0be06d7191e4c556d6f55142f83c732f.png

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Linux下搭建和简朴配置FTP服务器