解密Linux安全参数:保障系统安全,保护数据隐私 (linux的安全参数)

Linux操作系统的开源性、自由性和高可靠性在全球范围内获得了广泛应用。不过,为了确保在Linux系统上运行的应用程序和数据的安全,需要一系列安全参数的加固和配置。本文将介绍几个重要的Linux安全参数,以确保系统的安全性和数据隐私性。

一、物理访问控制

物理访问控制是Linux系统中最基础的安全控制方法。物理安全措施可以保护计算机免受未经授权的访问、窃取或破坏。例如,在计算机房中使用电子门禁系统、监控设备或密码锁等安全设施来控制物理访问。此外,也应定期检查硬件设备的完整性,包括硬盘、内存等,如果出现损坏或更换的情况,也应及时检查更换者身份以确保信息安全。

二、访问控制列表

Linux系统中一般采用的访问控制方法有访问控制列表(ACLs)和基于角色的访问控制(RBACs)等。ACLs是用于控制文件和目录权限的工具。通过ACLs,可以对每个文件和目录的访问权限进行单独控制。例如,在访问一个目录时,需要提供用户名和密码来验证身份,以获得访问权限。此外,也可以通过ACLs对文件的所有者和组进行访问控制。

三、防火墙

防火墙是一种可以防止恶意软件和网络攻击的工具。Linux系统中常用的防火墙有iptables和firewalld,可以通过这两个工具来限制进入和离开系统的网络流量。例如,通过防火墙可以阻止未授权的访问和黑客攻击,以保护系统的安全性。

四、SSL/TLS加密

SSL/TLS加密协议是一种用于加密网络通信的安全协议。可以将数据加密后在网络上进行传输,以防止其他人查看或拦截通信。在Linux系统中,SSL/TLS加密可以应用在不同的应用程序中,如Apache、Nginx、Postfix等。对于传输敏感信息的网站、电子邮件和其他应用程序,使用SSL/TLS加密可以保护数据的安全和隐私。

五、定期备份

定期备份也是保障数据安全的一种有效方法。定期备份可以避免数据丢失或被破坏的风险。在Linux系统中,可以使用各种备份软件进行定期备份,如rsync、tar等等。此外,还可以将备份文件存储在本地或远程存储服务器中,以确保备份数据的安全性。

总体上,保护Linux系统安全和数据隐私的最终目的是保护企业或个人在信息化时代的利益,因此,应该采取一系列的有效措施来加强 Linux 系统的安全性。在支持Linux平台的企业环境中,IT专家和管理员应加倍努力,行之有效的 Linux 安全策略能够为公司保障信息和数据的安全。

相关问题拓展阅读:

selinux常用参数

1)ls命令

  在命令后加个 -Z 或者陵陵加 –context

  # ls -Z

  -rwxr-xr-x fu fu user_u:object_r:user_home_t azureus

  -rw-r–r– fu fu user_u:object_r:user_home_t Azureus2.jar

  -rw-r–r– fu fu user_u:object_r:user_home_t Azureus.png

  2)chcon

  更改文件的标签

  # ls –context test.txt

  -rw-r–r– root root root:object_r:staff_tmp_t test.txt

  # chcon -t etc_t test.txt

  # ls -lZ test.txt

  -rw-r–r– root root root:object_r:etc_t test.txt

  3)restorecon

  当这个文件在策略里有定义是,可以恢复原来的 文件标签。

  4)setfiles

  跟chcon一样可以更改一部分文件的标签,不需要对整个文件系统重新设定标签。

  5)fixfiles

  一般是对整个文件系统的, 后面一般跟 relabel,对整个系统 relabel后,一般我们都重新启动。如果,在根目录下有.autorelabel空文件的话,每次重新启动时都调用 fixfiles relabel

  6)star

  就是tar在SELinux下的互换命令,能把文件的标签也一起备份起来。

  7)cp

  可以跟 -Z, –context=CONTEXT 在拷贝的时候指定目的地文件的security context

  8)find

  可以跟 –context 查特定的type的文件。

  例子:

  find /home/fu/ –context fu:fu_r:amule_t -exec ls -Z {} \:

  9)run_init

  在sysadm_t里手动启动一些如Apache之类的程序尺携戚,也可以让它正常进行,domain迁移隐高。

了解和配置 SELinux

1. 获取当前 SELinux 运行状态

getenforce

可能返回结果有三种:Enforcing、Permissive 和 Disabled。Disabled 代表 SELinux 被禁用,Permissive 代表仅记录安全警告但不阻止 可疑行为,Enforcing 代表记录警告且阻止可疑行为。

目前常见发行版中,RHEL、CentOS、Fedora 等默认设置为 Enforcing,其余的如 openSUSE 等为 Permissive。

2. 改变 SELinux 运行状态

setenforce

该命令可以立刻改变 SELinux 运行状态,在 Enforcing 和 Permissive 之间切换,结果保持至关机。一个典型的如指搏用途是看看到底是不是 SELinux 导致某个服务或者程序无法运行。若是在 setenforce 0 之后服务或者程序依然无法运行,那么就可以肯定不是 SELinux 导致的。

若是想要永久变更系统 SELinux 运行环境,可以通过更改配置文件 /etc/selinux/config 实现。注意当从 Disabled 切换到 Permissive 或者 Enforcing 模式后需要重启计算机并为整个文件系统重新创建安全标签(touch /.autorelabel && reboot)。

# vim /etc/selinux/config

# 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=enforcing

# SELINUXTYPE= can take one of these two values:

# targeted – Targeted processes are protected,

# mls – Multi Level Security protection.

SELINUXTYPE=targeted

3. SELinux 运行策略

配置文件 /etc/selinux/config 还包含了 SELinux 运行策略的信息,通过改变变量 SELINUXTYPE 的值实现,该值有两种可能: targeted 代表仅针对预制的几种网络服务和逗蠢访问请求使用 SELinux 保护,strict 代表所有网络服务和访问请求都要经过 SELinux。

RHEL、CentOS、Fedora 等默认设渣祥置为 targeted,包含了对几乎所有常见网络服务的 SELinux 策略配置,已经默认安装并且可以无需修改直接使用。 若是想自己编辑 SELinux 策略,也提供了命令行下的策略编辑器 seedit 以及 Eclipse 下的编辑插件 eclipse-slide 。

4. coreutils 工具的 SELinux 模式

常见的属于 coreutils 的工具如 ps、ls 等等,可以通过增加 Z 选项的方式获知 SELinux 方面的信息。

4.1使用ps获取:

$ ps -auxZ |grep httpd |head -5

Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ unconfined_u:system_r:httpd_t:s0 apache.0 0.? S Jun27 0:01 /usr/in/httpd unconfined_u:system_r:httpd_t:s0 apache.0 1. ? S Jun27 0:02 /usr/in/httpd unconfined_u:system_r:httpd_t:s0 apache.0 1. ? S Jun27 0:02 /usr/in/httpd unconfined_u:system_r:httpd_t:s0 apache.0 1. ? S Jun27 0:02 /usr/in/httpd unconfined_u:system_r:httpd_t:s0 apache.0 1. ? S Jun27 0:03 /usr/in/httpd

4.2使用ls获取

$ ls -Z /var/www/ drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_content_t:s0 error drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_content_t:s0 html drwxrwxrwx. apache barlow unconfined_u:object_r:httpd_sys_content_t:s0 icons drwxrwxrwx. apache barlow system_u:object_r:httpd_sys_content_t:s0 lost+found

以此类推,Z 选项可以应用在几乎全部 coreutils 工具里。

5、常用修改有关httpd服务的SELinux策略方法:

如上,ls -Z方法查询到的文件SELinux上下文跟默认要求的不匹配,则服务无法正常使用,如SELinux要求httpd服务的网页目录或文件的上 下文要为httpd_sys_content_t,否则客户端无法访问。

5.1使用chcon修改httpd目录或文件安全上下文:

如nagios服务器的网页目录上下文默认为unconfined_u:object_r:usr_t:s0,则客户端无法访问:

# ll -Z /usr/local/nagios/share/

-rwxrwxr-x. nagios apache system_u:object_r:usr_t:s0 config.inc.php

drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 contexthelp

drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 docs

drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 images

drwxrwxr-x. nagios apache unconfined_u:object_r:usr_t:s0 includes

-rwxrwxr-x. nagios apache system_u:object_r:usr_t:s0 index.html

-rwxrwxr-x. nagios apache system_u:object_r:usr_t:s0 index.php

……以下略……

使用chcon修改/usr/local/nagios/share/目录及其下所有文件安全上下文为unconfined_u:object_r:httpd_sys_content_t

# chcon -R unconfined_u:object_r:httpd_sys_content_t:s0 /usr/local/nagios/share/

查询结果:

# ls -Z /usr/local/nagios/share/

-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 config.inc.php

drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 contexthelp

drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 docs

drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 images

drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 includes

-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 index.html

-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 index.php

drwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 locale

-rwxrwxr-x. nagios apache unconfined_u:object_r:httpd_sys_content_t:s0 main.html

不用重启httpd服务,客户端就已经可以访问。

5.2使用semanage工具,让httpd支持非标准端口:

semanage工具非常强大,基本能实现所有SELinux配置,但很多时候我们并不知道SELinux错在哪里,在图形界面下有图形化的分析工具,在 终端界面下也有一个功能非常强大的分析工具sealert,但默认情况下,这两个工具都没有被安装,需要先安装semanage和sealert工具:

# yum -y install policycoreutils-python setroubleshoot

注:semanage的使用也可以参见我的另外一篇博文:Selinux管理工具semanage。

默认情况下 Apache 只侦听 80、443等几个端口,若是直接指定其侦听 808 端口的话,会在 service httpd restart 的时候报错:

# service httpd start

正在启动 httpd:(13)Permission denied: make_sock: could not bind to address 0.0.0.0:808

no listening sockets available, shutting down

Unable to open logs

查看/var/log/messages 文件,可以看到如下这样的错误:

# tail /var/log/messages

Jun 29 10:30:51 web2 setroubleshoot: SELinux is preventing /usr/in/httpd from name_bind access on the tcp_socket . For complete SELinux messages. run sealert -l 2ad073a4-7cff-9d78f75133af

根据提示,运行sealert -l 2ad073a4-7cff-9d78f75133af,生成SELinux报告如下:

# sealert -l 2ad073a4-7cff-9d78f75133af

# semanage port -a -t PORT_TYPE -p tcp 808

其中 PORT_TYPE 是以下之一:ntop_port_t, http_cache_port_t, http_port_t, puppet_port_t, jboss_messaging_port_t, jboss_management_port_t。

根据提示,运行semanage port -a -t PORT_TYPE -p tcp 808,此处需将PORT_TYPE替换为 http_port_t

# semanage port -a -t http_port_t -p tcp 808

查询结果:

# semanage port -l|grep http

http_cache_port_t tcp 3128, 8080, 8118, 8123,

http_cache_port_t udp 3130

http_port_t tcp 808, 80, 443, 488, 8008, 8009,##可以看到808端口已经加入

pegasus_http_port_t tcp 5988

pegasus_https_port_t tcp 5989

重启服务:

# service httpd start

正在启动 httpd:

5.3 修改selinux布尔值,允许创建私人网站

若是希望用户可以通过在 ~/www/ 放置文件的方式创建自己的个人网站的话,那么需要在 Apache 策略中允许该操作执行。使用:

# setsebool httpd_enable_homedirs 1

默认情况下 setsebool 的设置只保留到下一次重启之前,若是想永久生效的话,需要添加 -P 参数,比如:

# setsebool -P httpd_enable_homedirs 1

setsebool 是用来切换由布尔值控制的 SELinux 策略的,当前布尔值策略的状态可以通过 getsebool 来获知。 查看与httpd相关的布尔值:

# getsebool -a |grep http

allow_httpd_anon_write –> off

allow_httpd_mod_auth_ntlm_winbind –> off

allow_httpd_mod_auth_pam –> off

allow_httpd_sys_script_anon_write –> off

httpd_builtin_scripting –> on

httpd_can_check_spam –> off

httpd_can_network_connect –> off

httpd_can_network_connect_cobbler –> off

httpd_can_network_connect_db –> on

httpd_can_network_memcache –> off

httpd_can_network_relay –> off

httpd_can_sendmail –> off

httpd_dbus_avahi –> on

httpd_enable_cgi –> on

httpd_enable_ftp_server –> off

httpd_enable_homedirs –> on

httpd_execmem –> off

httpd_manage_ipa –> off

httpd_read_user_content –> off

httpd_run_stickshift –> off

httpd_setrlimit –> off

httpd_ssi_exec –> off

httpd_tmp_exec –> off

httpd_tty_comm –> on

httpd_unified –> on

httpd_use_cifs –> off

httpd_use_gpg –> off

httpd_use_nfs –> on

httpd_use_openstack –> off

httpd_verify_dns –> off

named_bind_http_port –> off

linux的安全参数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于linux的安全参数,解密Linux安全参数:保障系统安全,保护数据隐私,selinux常用参数的信息别忘了在本站进行查找喔。


数据运维技术 » 解密Linux安全参数:保障系统安全,保护数据隐私 (linux的安全参数)