您的位置:首页 > 编程语言 > PHP开发

ubuntu 使用vsftpd 创建FTP服务(用户名密码登录,限制列出目录)

2018-02-10 12:11 537 查看
vsftpd介绍

ubuntu 安装 vsftpd

配置vsftpd
备份vsftpdconfig

编辑vsftpdconfig

创建登录用户

添加vsftpd 登录用户

添加vsftpd登录用户对目录树的权限

重启 vsftpd 服务

验证ftp服务

vsftpd介绍

vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点。vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux、BSD、Solaris、 HP-UNIX等系统上面,是一个完全免费的、开放源代码的ftp服务器软件,支持很多其他的 FTP 服务器所不支持的特征。比如:非常高的安全性需求、带宽限制、良好的可伸缩性、可创建虚拟用户、支持IPv6、速率高等。

vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。

摘自百度百科-vsftpd

ubuntu 安装 vsftpd

$ sudo apt-get install vsftpd


使用apt安装即可。

配置vsftpd

备份vsftpd.config

$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig


编辑vsftpd.config

手动修改配置,根据下方的patch文件改一下。

$ sudo vim /etc/vsftpd.config


但是既然做了程序员就要懒一点,能自动就自动好了将配置好的文件与原始文件使用diff 生成的patch 文件,保存到本地,用patch命令更新即可。

--- /etc/vsftpd.conf.orig   2018-02-08 13:39:05.983282023 +0800
+++ /etc/vsftpd.conf    2018-02-10 11:14:15.584088172 +0800
@@ -28,11 +28,11 @@
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
-#write_enable=YES
+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
+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
@@ -67,11 +67,11 @@
#
# You may override where the log file goes if you like. The default is shown
# below.
-#xferlog_file=/var/log/vsftpd.log
+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
+xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
@@ -100,7 +100,7 @@
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
-#ftpd_banner=Welcome to blah FTP service.
+ftpd_banner=Welcome Lincoln Linux FTP Service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
@@ -120,9 +120,9 @@
# 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_enable=YES
# (default follows)
-#chroot_list_file=/etc/vsftpd.chroot_list
+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
@@ -142,7 +142,7 @@
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.
@@ -152,4 +152,8 @@

#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
-#utf8_filesystem=YES
+utf8_filesystem=YES
+userlist_enable=YES
+userlist_deny=NO
+userlist_file=/etc/vsftpd.user_list
+allow_writeable_chroot=YES


懒得手动改,可以将上面的patch 文件保存到机器上,然后使用

$ cd /
$ sudo  patch -p0 < [patch文件路径]


这样就将配置更新了。

创建登录用户

#先创建ftp目录
$ sudo mkdir /home/ftpdir
#添加用户
$ sudo useradd -d /home/ftpdir -s /bin/bash ftpuser
#设置用户密码
$ sudo passwd ftpuser
#设置ftp目录用户权限
$ sudo chown ftpuser:ftpuser /home/ftpdir


添加vsftpd 登录用户

#新建文件/etc/vsftpd.user_list,用于存放允许访问ftp的用户:
$ sudo touch /etc/vsftpd.user_list
$ sudo vim /etc/vsftpd.user_list


在/etc/vsftpd.user_list中添加允许登录ftp 的用户

ftpuser

添加vsftpd登录用户对目录树的权限

#新建文件/etc/vsftpd.chroot_list,设置可列出、切换目录的用户:
$ sudo touch /etc/vsftpd.chroot_list
$ sudo vim /etc/vsftpd.chroot_list


在/etc/vsftpd.chroot_list 设置可列出、切换目录的用户

ftpuser

重启 vsftpd 服务

$ sudo service vsftpd restart


验证ftp服务

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐