linux ftp配置(centos

本文介绍如何安装VSFTPD并配置匿名用户权限,包括设置SELinux为宽容模式以确保FTP服务正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主要流程:
1、 安装vsftpd 新建用户等信息
2、配置和设置权限
3、 如果系统装有 seliunx,需要改成宽容模式或关闭

[root@kunlong ~]# yum install vsftpd -y
[root@kunlong ~]# chkconfig vsftpd on
[root@kunlong ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES 允许匿名登录
anon_upload_enable=YES 允许匿名上传
anon_mkdir_write_enable=YES 允许匿名建立目录
write_enable=YES 允许ftp写
[root@kunlong ~]# setsebool -P allow_ftpd_anon_write on 设置selinux允许写
[root@kunlong ~]# getsebool -a|grep ftp
allow_ftpd_anon_write --> on
[root@kunlong var]# chmod 755 /var/ftp
[root@kunlong ~]# cd /var/ftp/pub/
[root@kunlong ftp]# mkdir upload
[root@kunlong ftp]# cd pub
[root@kunlong pub]# ll -Z
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 upload
[root@kunlong pub]# chcon -t public_content_rw_t /var/ftp/pub/upload selinux上下文可读写
[root@kunlong pub]# chmod 777 upload/

SELinux 的启动、关闭与查看
1,并非所有的 Linux distributions 都支持 SELinux 的
目前 SELinux 支持三种模式,分别如下:
?enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了;
?permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;
?disabled:关闭,SELinux 并没有实际运作。

2,查看SELinux的模式
# getenforce
Enforcing <==就显示出目前的模式为 Enforcing

3,查看 SELinux 的政策 (Policy)?
[root@master oracle]# sestatus
SELinux status: enabled <==是否启动 SELinux
SELinuxfs mount: /selinux <==SELinux 的相关文件资料挂载点
Current mode: enforcing <==目前的模式
Mode from config file: enforcing <==设定档指定的模式
Policy version: 21
Policy from config file: targeted <==目前的政策为何?

4,通过配置文件调整SELinux的参数
[root@www ~]# vi /etc/selinux/config
SELINUX=enforcing <==调整 enforcing|disabled|permissive
SELINUXTYPE=targeted <==目前仅有 targeted 与 strict

5,SELinux 的启动与关闭
【重要常识】上面是预设的政策与启动的模式!你要注意的是,如果改变了政策则需要重新开机;如果由 enforcing 或 permissive 改成 disabled ,或由 disabled 改成其他两个,那也必须要重新开机。这是因为 SELinux 是整合到核心里面去的, 你只可以在 SELinux 运作下切换成为强制 (enforcing) 或宽容 (permissive) 模式,不能够直接关闭 SELinux 的!
同时,由 SELinux 关闭 (disable) 的状态到开启的状态也需要重新开机啦!所以,如果刚刚你发现 getenforce 出现 disabled 时, 请到上述文件修改成为 enforcing 吧!

【重点】如果要启动SELinux必须满足以下两个点:
所以,如果你要启动 SELinux 的话,请将上述的 SELINUX=enforcing 设定妥当,并且指定 SELINUXTYPE=targeted 这一个设定, 并且到 /boot/grub/menu.lst 这个文件去,看看核心有无关闭 SELinux 了呢?
[root@www ~]# vi /boot/grub/menu.lst
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-92.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/1 rhgb quiet selinux=0
initrd /initrd-2.6.18-92.el5.img
# 如果要启动 SELinux ,则不可以出现 selinux=0 的字样在 kernel 后面!
【问题】通过上面的学习我们知道,如果将启动着的SELinux改为禁用,需要重启电脑,我们不想重启电脑又不想开启SELinux该怎么办呢?
【答案】将强制模式改为宽松模!
[root@www ~]# setenforce [0|1]
选项与参数:
0 :转成 permissive 宽容模式;
1 :转成 Enforcing 强制模式

范例一:将 SELinux 在 Enforcing 与 permissive 之间切换与查看
[root@www ~]# setenforce 0
[root@www ~]# getenforce
Permissive
[root@www ~]# setenforce 1
[root@www ~]# getenforce
Enforcing

6,查看已启动程序的type设定
[root@master oracle]# ps aux -Z
LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
system_u:system_r:init_t root 1 0.0 0.4 2060 520 ? Ss May07 0:02 init [5
system_u:system_r:kernel_t root 2 0.0 0.0 0 0 ? S< May07 0:00 [migra]
system_u:system_r:kernel_t root 11 0.0 0.0 0 0 ? S< May07 0:00 [kacpi]
system_u:system_r:auditd_t root 4022 0.0 0.4 12128 560 ? S<sl May07 0:01 auditd
system_u:system_r:auditd_t root 4024 0.0 0.4 13072 628 ? S<sl May07 0:00 /sbin/a
system_u:system_r:restorecond_t root 4040 0.0 4.4 10284 5556 ? Ss May07 0:00 /usr/sb

说明:其实这些东西我们都不用管,都是SELinux内置的。只要学会在强制和宽松模式间转换就行了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值