vsftpd架设(配置pam模块)
Vsftpd 是很安全的ftp软件
VSFTPD的目录结构
/usr/sbin/vsftpd: VSFTPD的可执行文件
/etc/rc.d/init.d/vsftpd:启动脚本
/etc/vsftpd/vsftpd.conf:主配置文件
/etc/pam.d/vsftpd:PAM认证文件
/etc/vsftpd.ftpusers:禁用使用VSFTPD的用户列表文件
/etc/vsftpd.user_list:禁止或允许使用VSFTPD的用户列表文件
/var/ftp:匿名用户主目录
一,安装vsftpd
sudo aptitude install vsftpd
二,配置
注意,等号“=”两边不能有空格
1,备份主配置表
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.backup
然后打开此配置表,
sudo gedit /etc/vsftpd.conf
ctrl+f 找到
anonymous_enable=YES
# 是否允许匿名FTP访问。
local_enable=YES
# 是否允许本地用户访问,这里虚拟用户也是本地用户
write_enable=YES
#是否允许所有用户都上传文件
local_umask=027
# vsftpd的默认umask是077,即,屏蔽除了创建者以外所有的用户的权限,如果觉得这样没必要,可以设置为022,这样其他用户可读。
anon_upload_enable=YES
#是否允许匿名用户上传
ftpd_banner=Welcome to blah FTP service
# 用户连接后看到的欢迎信息
pam_service_name=vsftpd
# PAM 服务名称,这里的设置决定PAM将为vsftpd使用配置文件
#/etc/pam.d/vsftpd
除了local_enable和ftpd_banner 之外,其他设置都很好地适应我们的需求,因此不需改动。
虚拟用户和真实用户?
真实用户,是在这台机器上登录的用户,比如安装系统时的用户。
虚拟用户,是创立的用户,只能登录ftp,而不能登录系统,不是系统的用户。这样比较安全。
为了使用虚拟用户,还需要加入以下设置:
guest_enable=YES
guest_username=ftp
user_config_dir=/etc/vsftpd_user_conf
这样使虚拟用户在系统中具有系统用户使用ftp的权限。系统用户ftp无法在终端登录,他是FTP服务目录的拥有者,最后一行为今后服务,是配置用户的目录。
4,配置PAM模块
由于安全考虑,不希望vsftpd共享本地系统的用户认证信息,而采用自己独立的用户认证数据库来认证虚拟用户。这样,虚拟用户和真是的用户不必采用相同的用户名和口令。
和linux下面大多数需要用户认证的程序一样,vsftpd也采用PAM作为后端,可插拔的认证模块来集成各种不同的认证方式。
在这里,可以通过修改vsftpd的PAM配置文件
/etc/pam.d/vsftpd来决定vsftpd使用何种认证方式,
可以是本地系统的真实用户认证(模块pam_unix),也可以是独立的用户认证数据库(模块pam_userdb),也可以是网络上的LDAP数据库(模块pam_ldap)等。所有这些模块都存放在/lib/security/目录(对AMD64则是/lib64/security/)下。
这里采用pam_userdb模块,该模块采用独立的Berkeley DB 格式(Berkeley DB 是 Unix平台最常见的数据持久化格式,有各种版本,这里假设系统采用4.6版本)的用户认证数据库。为了建立Berkeley Db式的数据库,需要安装db4.6-util 软件包。
$ sudo aptitude install db4.6-util
建立一个db 格式数据库的一般方式是先编辑一个文本文件,将键值和对应的数据写在相邻的行中。比如下面,我建立logins.txt的文档,内容如下:
upo
magic
longxibendi
1234
根据pam_userdb 模块的约定,键值就是用户名,对应的数据则是口令。所以,这个文本文档中的奇数行为用户名,用户名的下一行就是其对应的口令。
下面将文档logins.txt转换为berkeley Db格式,并使他对应用户为不可读:
sudo db4.6_load -T -t hash -f logins.txt /etc/vsftpd_login.db
sudo chmod 600 /etc/vsftpd_login.db
rm logins.txt #这是删除logins.txt文档
然后编辑 /etc/pam.d/vsftpd
注释掉或者删除掉原有的所有内容,
加入这几行:
# /etc/pam.d/vsftpd
auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login
让PAM采用相应的认证模块和刚刚建立的用户数据库。
重新启动 vsftpd之后,虚拟用户设置就生效了。
sudo invoke-rc.d vsftpd restart
至此,用户upo 或者 longxibendi 已经可以用相应的用户名和口令登录FTP了。
5,分用户设置
上面设置了两个用户分别是upo和longxibendi
接下来相让upo 可以上传文件,但是不希望longxibendi也有同样的权限 ,借助vsftpd提供的分用户 设置机制,可以容易的做到这一点。
上文,已经在/etc/vsftpd.conf 中加入了
user_config_dir 设置,现在只需建立相应的目录,并在该目录下增加用户upo的配置文件即可:
代码:
sudo mkdir /etc/vsftpd_user_conf
#建立文件夹,在/etc/下,名字是#vsftpd_user_conf
#这样才可以与上面的配置相对应。
代码:
sudo sh -c “echo 'write_enable=YES' > /etc/vsftpd_user_conf/upo”
# 将 内容write_enable=YES 写
# 入/etc/vsftpd_user_conf/upo
# 而,write_enable=YES的意思是允许写操作
代码:
sudo sh -c “echo 'anno_upload_enable=YES' >> / /etc/vsftpd_user_conf/upo
# 按行,也就是为什么要用‘>> /’将
# anno_upload_enable=YES写
# 入/etc/vsftpd_user_conf/upo 中
# anno_upload_enable=YES 允许用户上传
代码:
sudo sh -c “echo 'anno_mkdir_write_enable=YES' >> / /etc/vsftpd_user_conf/upo”
# 也是写入...内容到...
# anno_mkdir_write_enable=YES 意思是
# 允许建立文件夹
如果允许用户upo删除和重命名文件(不建议)
执行:
sudo sh -c “echo 'anon_other_write_enable=YES' >> / /etc/vsftpd_user_conf/upo”
然后运行下面的命令,让vsftpd读入新配置
代码:
sudo invoke-rc.d vsftpd reload
现在用户upo 可以上传文件了,作为站点管理员,可能希望文件只能被上传到限定的目录,所以运行下面:
sudo mkdir /home/ftp/incoming
# 建立文件夹incoming 在/home/ftp/下
sudo chown ftp:nogroup incoming
sudo chmod 770 /home/ftp/incoming
sudo chmod -w /home/ftp
# 上面的命令是配置文家夹的属性
这样,目录/home/ftp对ftp用户,也就是隐藏在所有虚拟用户背后的真实用户不可写了,因此上传到/home/ftp不会成功。
注意,上面的例子中屏蔽了一般用户对/home/ftp/incoming 的访问权限,这样做是为了利用vsftpd的一个副作用。
在默认的情况下,虚拟用户只能读取,或者下载对于任何用户都可读的文件和目录。上面的设置使虚拟用户无法列出目录 /home/ftp/incoming 下的文件,通常这是一个不错的特性。另一方面,通常,会希望upo用户,也可以看到自己上传的文件,为此可以运行如下命令:
代码:
sudo sh -c “echo 'anno_world_readable_only=NO' >> / etc/vsftpd_user_conf/upo”
# 将... 写入...文档
# anno_world_readable_only=NO 意思是
# 取消用户的只读限制,不加这句,用户不能查看自
# 己上传的文件。
代码:
sudo killall -l vsftpd
sudo /etc/init.d/vsftpd restart
现在用户upo 可以看到/home/ftp/incoming 的内容了,完美主义者,可在/etc/vsftpd_user_conf/upo
中加入下面两行
local_umask=027
以彻底化副作用。
6,注意:
(1),上面的添加文档内容的命令,可以用gedit 来完成。
(2),配置表中的'='号两边不能有空格
(3),上面的关于/etc/vsftpd_user_conf/upo并没有配置下载权限,实际上默认是可以下载文件的。包括,我们并没有配置用户longxibendi的权限,但他也可以下载文件。
7,下面是我的配置表:
第一个/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=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# 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=027
#
# 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
#
# 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/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=NO
#
# 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=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().
#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
#
#
# Debian customization
#
# Some of vsftpd's settings don't fit the Debian filesystem layout by
# default. These settings are more Debian-friendly.
#
# 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
#
# 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
# This option specifies the location of the RSA key to use for SSL
# encrypted connections.
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
guest_enable=YES
guest_username=ftp
user_config_dir=/etc/vsftpd_user_conf
第二个 /etc/pam.d/vsftpd
# # Standard behaviour for ftpd(8).
# auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
# Note: vsftpd handles anonymous logins on its own. Do not enable
# pam_ftp.so.
# Standard blurb.
# @include common-account
# @include common-session
# @include common-auth
# auth required pam_shells.so
# 上面的行,是原有的。
# /etc/pam.d/vsftpd
auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login
第三个 logins.txt
upo
magic
longxibendi
1234
第四个 /etc/vsftpd_user_conf/upo
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_world_readable_only=NO
anon_other_write_enable=YES
#上面这行是是否允许删除和重命名操作
local_umask=027
参考资料:
《Ubuntu实战技巧精粹》 何晓龙 编著 人邮出版社
《Ubuntu linux从入门到精通》 郝铃,李晓 编著
http://forum.ubuntu.org.cn/viewtopic.php?f=54&t=117505
http://doc.linuxpk.com/4233.html(推荐)
vsftpd架设(配置pam模块)的更多相关文章
- vsftpd安装配置虚拟用户
原文发表于cu:2016-03-11 参考文档: FTP原理:http://vbird.dic.ksu.edu.tw/linux_server/0410vsftpd_1.php FTP配置:http: ...
- Linux安装vsftpd及配置详解
1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件.[root@bogon ~]# yum -y install vsftpd 2.FT ...
- Linux下PAM模块学习总结
在Linux中执行有些程序时,这些程序在执行前首先要对启动它的用户进行认证,符合一定的要求之后才允许执行,例如login, su等.在Linux中进行身份或是状态的验证程序是由PAM来进行的,PAM( ...
- [转] linux中pam模块
一.pam简介 Linux-PAM(linux可插入认证模块)是一套共享库,使本地系统管理员可以随意选择程序的认证方式. 换句话说,不用(重新编写)重新编译一个包含PAM功能的应用程序,就可以改变它使 ...
- Centos6.9安装vsftpd并配置多用户的方法
本文介绍了Centos6.9安装vsftpd并配置多用户的方法,分享给大家,具体如下: 一.安装vsftpd ? 1 2 3 4 5 6 7 8 #安装vsftpd yum -y install vs ...
- linux中pam模块
https://www.cnblogs.com/ilinuxer/p/5087447.html linux中pam模块 一.pam简介 Linux-PAM(linux可插入认证模块)是一套共享库,使本 ...
- centos关于vsftpd的配置、配置说明及常见问题
一.安装vsftpd 安装yum install -y vsftpd 开机启动 chkconfig vsftpd on 启动 service vsftpd start 加入防火墙 vi /etc/sy ...
- 一起来学linux:PAM模块
在Linux中执行有些程序时,这些程序在执行前首先要对启动它的用户进行认证,符合一定的要求之后才允许执行,例如login, su等 在Linux中进行身份或是状态的验证程序是由PAM来进行的,PAM( ...
- vsftpd 安装配置
# vsftp 安装yum install vsftpd -y # 配置用户名密码时需要yum install db* db4* -y# 启动vsftpdservice vsftpd start # ...
随机推荐
- SpringBoot2.1.9+dubbo2.7.3+Nacos1.1.4构建你的微服务体系
简单几步使用最新版本的DUBBO构建你的微服务体系 NACOS注册中心 从github下载最新版本的nacos 上传至服务器并解压 单机启动sh startup.sh -m standalone na ...
- 超融合与传统IT架构对比:成本价格优势有哪些
之前文章中,我们已经介绍了超融合给用户 IT 基础架构带来的各个方面的价值,其中成本只是超融合架构的优势之一.但很多用户还是会非常关心这个话题,希望能有更具体的了解,所以本文整理超融合和传统 FC S ...
- 提高首屏页面加载速度,解决vue-cli打包后单个文件过大的问题
本教程是针对vue-cli3以上的版本,其实原理都大同小异,这个demo为vue-cli直接创建的项目,并在main.js中引入了echart.element-ui.lodash 首先看demo打包后 ...
- 还不会用FindBugs?你的代码质量很可能令人堪忧
前言 项目中代码质量,往往需要比较有经验的程序员的审查来保证.但是随着项目越来越大,代码审查会变得越来越复杂,需要耗费越来越多的人力.而且程序员的经验和精力都是有限的,能审查出问题必定有限.而在对代码 ...
- CSP2019知识点整理
也算是接下来二十天的复习计划吧 仅止于联赛难度左右 基础算法 字符串 char[] cstring memset() 输入无& gets(), fgets(stdin, ,); strcmp, ...
- 【Java必修课】String.intern()原来还能这么用(原理与应用)
1 简介 String.intern()是JDK一早就提供的native方法,不由Java实现,而是底层JVM实现,这让我们对它的窥探提高了难度.特别是在Oracle收购了Sun公司后,源代码不开源了 ...
- Hadoop3.2.1版本的环境搭建
最近有人提出能不能发一些大数据相关的知识,No problem ! 今天先从安装环境说起,搭建起自己的学习环境. Hadoop的三种搭建方式以及使用环境: 单机版适合开发调试: 伪分布式适合模拟集群学 ...
- 小白学 Python(21):生成器基础
人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...
- Linux 学习(1) | 学习方向导图
方向导图 文件系统导图 内核导图
- python多线程总结
概述 进程与线程 进程:进程是资源(CPU.内存等)分配的最小单位,进程有独立的地址空间与系统资源,一个进程可以包含一个或多个线程 线程:线程是CPU调度的最小单位,是进程的一个执行流,线程依赖于进程 ...