- 论坛徽章:
- 0
|
先查看vsftp是否支持pam模块
?
# ldd /usr/sbin/vsftpd
libpam.so.0 => /lib/libpam.so.0 (0x009e3000) # 有这个输出就对了
添加虚拟账户映射的本地账户(因为 虚拟账户要操作本地的文件,所使用的权限就是本地账户的权限,所以要把虚拟账户映射成本地账户)
?
# useradd -s /sbin/nologin vuser
下面是vsftpd.conf的配置文件
?
anonymous_enable=NO
local_enable=YES #因为要映射成本地账户,所以这里必须为yes
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
chroot_local_user=YES #把本地账户限制在设定的目录中
ls_recurse_enable=NO #禁止 ls -R 递归显示子目录
listen=YES
pam_service_name=vsftpd #修改/etc/pam.d/vsftpd
userlist_enable=YES
tcp_wrappers=YES
user_config_dir=/etc/vsftpd/vuser_conf #虚拟账户的配置目录,在此目录可以单独对每个虚拟账户做特殊设定,会覆盖vsftpd.conf的配置
virtual_use_local_privs=YES #让虚拟账户拥有本地映射账户的权限
下面是虚拟账户的配置文件(在/etc/vsftpd/vuser_conf)
?
#cat /etc/vsftpd/vuser_conf/web_user
guest_enable=YES #启用虚拟账户支持
guest_username=vuser #映射的本地账户名称
local_root=/var/ftp #此虚拟账户对应的ftp根目录,可以对每个虚拟账户设定不同的ftp根目录
write_enable=yes #此设定是下面几个设定的基础
anon_world_readable_only=YES #只允许下载文件
anon_upload_enable=YES #可以上传文件
anon_mkdir_write_enable=YES #可以建立目录,但不能改名和删除
anon_other_write_enable=YES #可以改名和删除
ps: 详细说明可以 man 5 vsftpd.conf
看看这个选项的说明:
anon_upload_enable
If set to YES, anonymous users will be permitted to upload files under certain conditions. For this to work, the option
write_enable must be activated, and the anonymous ftp user must have write permission on desired upload locations. This
setting is also required for virtual users to upload; by default, virtual users are treated with anonymous (i.e. maximally
restricted) privilege.
Default: NO
修改/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
auth sufficient /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account sufficient /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
db=/etc/vsftpd/vsftpd_login 这个文件就是我们稍候建立的虚拟账户文件
添加虚拟账户
文件格式是:一行用户名,一行密码
?
# cat vsftpd_login.txt
web_user
123456
web_test
654321
还要处理成pam识别的Berkeley DB文件格式
?
db_load -T -t hash -f vsftpd_login.txt vsftpd_login.db
db_load 由 db4-utils 软件包提供.
这里注意生成的文件名是 vsftpd_login.db,我们写到/etc/pam.d/vsftpd里是不写后缀名的!
下面是我们建立的vsftpd的配置文件清单
?
# ll /etc/vsftpd/
总用量 40
-rw------- 1 root root 125 3月 4 2011 ftpusers
-rw------- 1 root root 361 3月 4 2011 user_list
-rw------- 1 root root 4708 9月 7 00:01 vsftpd.conf
-rwxr--r-- 1 root root 338 3月 4 2011 vsftpd_conf_migrate.sh
-rw-r--r-- 1 root root 12288 9月 6 23:11 vsftpd_login.db
-rw-r--r-- 1 root root 26 9月 6 23:10 vsftpd_login.txt
drwxr-xr-x 2 root root 4096 9月 7 00:20 vuser_conf
注意事项:
1. 关闭selinux,修改后要重启系统.
cat /etc/sysconfig/selinux
?
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
2. vuser_conf目录下的虚拟用户配置文件,要以用户命名.即你的vsftpd_login.txt里面有xiaoming这个账户,那么vuser_conf目录下就要有xiaoming这个文件
3. 你的本地映射账户是vuser,那么你建立这个账户的时候不能用 useradd -M 这样/home下没有vuser的家目录,也是无法登陆的
4. 虚拟用户的权限跟vuser的权限一样,所以你对虚拟用户设置的local_root=/dir 那么vuser用户也要对这个/dir目录有相应的权限才可以
5. 记得看下服务器的cpu架构,用arch命令
?
x86_64
如果系统是64位的,那么/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
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
补充:
怎么样让我们的网站文件目录权限更安全呢,要坚决杜绝777的权限设置,下面说下我的方法
让web server(apache/nginx)和php以nobody的身份运行,配置vsftp以虚拟用户vuser
然后设置网站目录和文件的属主属组为vuser:nobody,目录权限为750,普通文件为640.web server和php只对文件有读的权限。
还漏下一点,还要修改vuser的属组,不然虚拟用户上传的文件和目录属主和属组都是vuser,不符合我们的要求
usermod -g nobody vuser
如果按照上面vsftp的设置那么虚拟用户上传的文件和目录权限是这样的
-rw-rw-r-- 1 vuser nobody 2894 2月 24 19:48 1.txt
drwxrwxr-x 2 vuser nobody 4096 2月 24 19:49 aa
修改vsftpd.conf
local_umask=027
这样就符合要求了
drwxr-x--- 2 vuser nobody 4096 2月 24 20:04 dd
-rw-r----- 1 vuser nobody 3634 2月 24 19:56 2.txt
ok.
不对的地方欢迎指正
http://www.cnblogs.com/txwsqk/ |
|