本专栏提供售后服务,帮助解决问题,文章底部扫描进群即可
题目
Ftp
禁止使用不安全的FTP,请使用“CSK Global Root CA”证书颁发机构,颁发的证书,启用FTPS服务;
用户webadmin,登录ftp服务器,根目录为/webdata/;
登录后限制在自己的根目录;
允许WEB管理员上传和下载文件,但是禁止上传后缀名为.doc .docx .xlsx的文件。
限制用户的下载最大速度为100kb/s;最大同一IP在线人数为2人;
用于通过工具或者浏览器下载的最大速度不超过 100kb/s
一个IP地址同时登陆的用户进程/人数不超过2人。
一、关闭Selinux跟防火墙
setenforce 0
systemctl stop firewalld
二、安装vsftpd
yum install vsftpd -y
三、创建用户与目录并申请证书
[root@Server01 ~]# mkdir /webdata
[root@Server01 ~]# chmod 777 /webdata/
[root@Server01 ~]# useradd webadmin
[root@Server01 ~]# passwd webadmin
Changing password for user webadmin.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
这只是其中方法之一,还可以将证书给CA根证书机构(Rserver)去签发
创建根证书
[root@Server01 ~]# vim /etc/pki/tls/openssl.cnf
dir = /CA
[root@Server01 ~]# mkdir /CA
[root@Server01 ~]# cp -rf /etc/pki/tls/* /CA
[root@Server01 ~]# cd /CA/
[root@Server01 CA]# touch index.txt
[root@Server01 CA]# echo 01 >serial
[root@Server01 CA]# openssl genrsa -out private/cakey.pem 2048
Generating RSA private key, 2048 bit long modulus
.+++
.................................................................................................................+++
e is 65537 (0x10001)
root@Server04:/CA# openssl req -new -x509 -key ./private/cakey.pem -out cacert.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Inc
Organizational Unit Name (eg, section) []:www.skills.com
Common Name (e.g. server FQDN or YOUR name) []:skill Global Root CA
Email Address []:
申请站点证书秘钥和请求证书
[root@Server01 CA]# openssl genrsa -out ftp.key 2048
Generating RSA private key, 2048 bit long modulus
..............................................................+++
................................................................+++
e is 65537 (0x10001)
[root@Server01 CA]# openssl req -new -key ftp.key -out ftp.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:China
Locality Name (eg, city) [Default City]:ShangDong
Organization Name (eg, company) [Default Company Ltd]:skills
Organizational Unit Name (eg, section) []:Operations Departments
Common Name (eg, your name or your server's hostname) []:ftp.sdskills.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
给证书签名
[root@Server01 CA]# openssl x509 -req -in ftp.csr -CA /CA/cacert.pem -CAkey /CA/private/cakey.pem -CAcreateserial -out ftp.crt
Signature ok
subject=/C=CN/ST=China/L=ShangDong/O=skills/OU=Operations Departments/CN=ftp.sdskills.com
Getting CA Private Key
四、编辑ftp配置文件
vim /etc/vsftpd/vsftpd.conf
五、测试
安装lftp
yum install lftp -y
编辑lftp配置文件加入一行
vim /etc/lftp.conf
set ssl:verify-certificate no
创建几个文件测试
touch test.doc
touch test.docx
touch test.xlsx
lftp连接测试
[root@Server01 ~]# lftp -u webadmin:Chinaskill22 localhost
lftp webadmin@localhost:~> quote pwd
257 "/"
lftp webadmin@localhost:/> put test.doc
put: Access failed: 550 Permission denied. (test.doc)
lftp webadmin@localhost:/> put test.docx
put: Access failed: 550 Permission denied. (test.docx)
lftp webadmin@localhost:/> put test.xlsx
put: Access failed: 550 Permission denied. (test.xlsx)
lftp webadmin@localhost:/> put test.txt
lftp webadmin@localhost:/> ls
-rw-r--r-- 1 1000 1000 0 Jul 21 11:24 test.txt
五、扩展内容
虚拟用户
ftp1能下载,但不能上传;
ftp2能上传,但不能下载。
1. 创建2个虚拟用户,并设置密码
[root@linux ~]# useradd -s /sbin/nologin -d /var/ftp1 ftp1
[root@linux ~]# useradd -s /sbin/nologin -d /var/ftp2 ftp2
[root@linux ~]# echo 111 | passwd --stdin ftp1
[root@linux ~]# echo 222 | passwd --stdin ftp2
以下步骤中的2,3,4可以不做,只不过是密码不是db格式的。
2. 安装db4
[root@linux vsftpd]# yum -y install db4 db4-utils
3. 建立密码文件(每个用户两行,第一行为用户名,第二行为密码)
[root@linux vsftpd]# cat vusers.txt
ftp1
111
ftp2
222
[root@linux vsftpd]# db_load -T -t hash -f vusers.txt vusers.db
4. 配置pam认证文件
[root@linux vsftpd]# vim /etc/pam.d/vsftpd
在最后添加下面的内容(注意:末尾没有.db)
auth required pam_userdb.so db=/etc/vsftpd/vusers
account required pam_userdb.so db=/etc/vsftpd/vusers
5. 编辑配置文件
[root@linux vsftpd]# vim vsftpd.conf
最后加上
guest_enable=YES
guest_username=ftp #本地用户映射为匿名用户
user_config_dir=/etc/vsftpd
6. 创建用户配置文件(配置文件名与用户名相同)
[root@linux vsftpd]# cat ftp1
local_root=/var/ftp1
download_enable=YES
anon_upload_enable=NO
[root@linux vsftpd]# cat ftp2
local_root=/var/ftp2
download_enable=NO
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
匿名用户
下载
# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
no_anon_password=YES #匿名用户不需要输入密码
download_enable=YES #默认为YES
anon_world_readable_only=NO #匿名用户能下载自己上传的文件。如果设为YES,则其他用户和匿名用户有读权限,才可以下载;如果设为NO,则其他用户和匿名用户没有写权限,也可以下载。匿名用户上传的文件权限为600.
匿名用户不能下载自己上传的文件(改变文件的所有者为daemon,匿名用户不能访问daemon的文件)
chown_uploads=YES
chown_username=daemon
上传
修改配置文件
# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
修改目录权限
# chmod o=rwx /var/ftp/pub
local_enable=YES
本地用户
chroot
情况一、
chroot_local_user=YES #将所有用户锁定在主目录,下面指定的用户例外
chroot_list_enable=YES #启用锁定用户名单。
chroot_list_file=/etc/vsftpd/chroot_list #文件中的用户有例外的权限。
则/etc/vsftpd/chroot_list文件中的用户不锁定到用户主目录,其余的用户锁定到用户主目录。
情况二、
chroot_local_user=NO #不锁定用户主目录,下面指定的用户例外
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
则/etc/vsftpd/chroot_list文件中的用户锁定到用户主目录,其余的用户不锁定到用户主目录。
情况三、
chroot_local_user=YES
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list
则/etc/vsftpd/chroot_list不生效,所有用户全部锁定在主目录。
729726992