#############################################################
一.vsftpd簡介
vftpd(Very Secure FTP),文件共享軟件。支持IPv6以及SSL加密。
vsftpd安全性主要體現的三方面:
進程分離,處理不同任務的進程是獨立運行的;
進程運行時,均已最小權限運行的;
多數進程都使用chroot進行禁錮,防止客戶訪問非法共享目錄;
安裝vsftpd:
yum install vsftpd -y
vsftpd相關的核心文件與目錄說明:
/etc/logrotate.d/vsftpd ##日誌輪轉備份配置文件
/etc/pam.d/vsftpd ##基於PAM的vsftpd驗證配置文件
/etc/rc.d/init.d/vsftpd ##vsftpd啓動腳本
/etc/vsftpd ##軟件主目錄
/etc/vsftpd/ftpusers ##默認的vsftpd黑名單
/etc/vsftpd/user_list ##臨時黑名單,可通過主配置文件設置爲白名單
/etc/vsftpd/vsftpd.conf ##vsftpd主配置文件
/usr/sbin/vsftpd ##vsftpd主程序
/var/ftp ##默認vsftpd共享目錄
#############################################################
二.匿名賬號登錄
vsftpd默認開啓的是匿名共享,默認共享路徑爲/var/ftp
anonymous_enable=YES
local_enable=YES
#############################################################
三.本地賬號登錄
vim /etc/vsftpd/vsftpd.conf
修改;
anony_enable=NO,默認共享路徑爲賬戶個人家目錄
!注意:開啓本地9賬戶登錄後,用戶可離開家目錄,從而進入系統中的其他目錄,這樣是很危險的,所以在文件中使用
chroot_local_user=NO,用戶將禁錮在自己的家目錄下
測試:
useradd -s /sbin/nologin tom
useradd -s /sbin/nologin jerry
useradd -s /sbin/nologin smith
touch /home/{tom,jerry,smith}/test.txt
setenforce 0
systemctl stop firewall
service vsftpd start
#############################################################
四.虛擬賬號登錄
1.創建虛擬用戶
vim /etc/vsftpd/userfile ##虛擬用戶名和密碼文件
添加:
westos1 ##用戶名1
123 ##用戶1密碼
westos2 ##用戶名2
123 ##用戶2密碼
westos3 ##用戶名3
123 ##用戶3密碼
db_load -T -t hash -f /etc/vsftpd/userfile /etc/vsftpd/userfile.db
## db_load :創建虛擬用戶
## -T :允許應用程序將文本文件轉譯載入數據庫
## -t : 指定轉譯載入的數據類型
## hash :hash碼加密
## /etc/vsftpd/userfile : 記錄用戶名和密碼
## /etc/vsftpd/userfile.db : hash加密過的文件
rm -fr /etc/vsftpd/userfile##刪掉虛擬用戶文件
2.修改vsftpd配置文件,設置相關參數
vim /etc/vsftpd/vsftpd.conf
添加:|
pam_service_name=vuser ##pam認證方式
userlist_enable=YES ##啓用userlist用戶列表文件
tcp_wrappers=YES ##啓動tcp_wrappers
guest_enable=YES ##所有的非匿名用戶登錄都映射爲guest_username指定的賬戶
guest_username=ftp ##設定來賓用戶
local_root=/ftpdir/$USER ##本地賬號訪問ftp的根路徑
#local_root=/var/ftp/pub/ ##本地賬號訪問ftp的根路徑
user_sub_token=$USER ##
allow_writeable_chroot=YES ##
user_config_dir=/etc/vsftpd/vuser-conf##
3.認證機制(賬號,密碼)
vim /etc/pam.d/vuser
添加
account required pam_userdb.so db=/etc/vsftpd/userfile
auth required pam_userdb.so db=/etc/vsftpd/userfile
4. 創建本地賬號的根目錄
mkdir /ftpdir/westos1
mkdir /ftpdir/westos2
mkdir /ftpdir/westos3
5.更改權限和組名
chmod 775 /ftpdir/westos*
chgrp ftp /ftpdir/westos*
systemctl restart vsftpd
6.
vim /etc/vstpd/vuser-conf/westos* ##匿名用戶的配置文件
添加:(任何你想給的權限,例子如下)
anon_upload_enable=YES
#############################################################
五.
vim /etc/selinux/config
chcon -t public_content_t /ftpdir -R
vim /etc/vsftpd/vsftpd.conf
+- anon_root=/ftpdir
vim /etc/selinux/config
reboot
vim /etc/selinuxconfig
reboot
semanage fcontext -a -t public_content_t '/ftpdir(/.*)?'
semanage fcontext -l |grep ftpdir
ls -Zd /ftpdir
restorecon -RvvF /ftpdir/
#############################################################
SELinux(Security-Enhanced Linux)
一.SELinux簡介
基於Linux內核的強制訪問控制機制,旨在增強傳統Linux操作系統的安慶性。
vim /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 three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
SELINUX總開關 三種狀態 enforcing、permissive、disabled
enforcing :強制開啓(會攔截非法的訪問,並記錄日至)
permissive :警告模式(會在SELinux日至中記錄,但不會攔截)
disabled :禁用(設置爲j禁用,應重新啓動計算機)
SELINUXTYPE=targeted 設置SELinux類型,類型兩種 ,targeted 、mls
targeted:主要對服務進程進行訪問控制
mls:對所有的進程進行控制
########################################################二.訪問及簡單設置
臨時設置(重啓後失效)
setenforce 0##設置SELinux爲permissive模式
setenforce 1##設置SELinux爲enforcing模式
永久模式(修改配置文件)
vim /etc/sysconfig/selinux
########################################################三.
SELinux會爲進程與文件添加安全信息標籤(SELinux用戶、角色、類型、級別)
(1)SELinux安全上下文
ls -Z查看文件或目錄的上下文信息
[root@foundation38 ~]# ls -Z anaconda-ks.cfg
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg
ps aux -Z 查看進程的上下文信息
semanage login -l##查看系統賬戶與SELinux賬戶之間的映射關係
[root@foundation38 kiosk]# semanage login -l
Login Name SELinux User MLS/MCS Range Service
__default__ unconfined_u s0-s0:c0.c1023 *
root unconfined_u s0-s0:c0.c1023 *
system_u system_u s0-s0:c0.c1023 *
(2)SELinux用戶被授予特定角色,角色被授予操作特定的域
(3)類型定義了進程的域以及文件的類型
(4)級別 MLS MCS
########################################################四.修改安全上下文
chcon -t admin_home_t /root/passwd ##修改文件安全上下文中的類型
chcon -R -t admin_hom_t /root/##遞歸修改目錄安全上下文
chcon --reference=/etc/passwd /root/passwd##