SELinux policies and rules-related commands Seinfo, Sesearch, Getsebool, Setsebool, Semanage

Source: Internet
Author: User

SELinux Policy and rule management related orders: Seinfo command, sesearch command, getsebool command, setsebool command, Semanage command.

Seinfo command

The Seinfo command is used to query the policies provided by SELinux to provide how many rules, a principal process can read to the target file resource is focused on the SELinux policy and the rules within the policy, and then through the definition of the rule to deal with the security context of the target file, especially the "type" Part.

-A: Lists all information about SELinux status, rule Boolean, Identity, role, type, and so on.

-T: Lists the kinds of SELinux all types (type).

-r: Lists the types of SELinux all roles (role).

-U: Lists the types of SELinux all identification (user).

-B: Lists the types of all Rules (Boolean).

Instance

List the rules related to httpd:

Seinfo-b | grep httpd


Sesearch command

If you find a correlation type or Boolean value and want to know the detailed rule, use the Sesearch command to query.

Grammar

Sesearch [-A] [-s principal type] [-t target type] [-B boolean]

Options

-A: Lists all relevant information for that type or Boolean value

-T: The type is also followed, such as-t httpd_t

-B: The next rule that will be followed by a Boolean value


Example

-B Httpd_enable_ftp_server Instance

Find information about the target file resource type httpd_sys_content_t:

Sesearch-a-T httpd_sys_content_t

Identify all information that the principal process is httpd_t and the target file type is HTTPD Related:

Sesearch-s httpd_t-t httpd_*-A

View Boolean value Httpd_enable_homedirs How many rules are set

Sesearch-b httpd_enable_homedirs-a


Getsebool command

is a Boolean value that is used to query the rules within the SELinux policy.

Grammar

Getsebool [-A] [Boolean terms]

Options

-A: Lists all Boolean terms above the current system set to on or off values.

Instance

Query all the Boolean settings in this system:

Getsebool-a

Networkmanager_disable_trans--

Off Allow_console_login--


Setsebool command

The Setsebool command is a Boolean value used to modify the rules within the SELinux policy. The Setsebool command and the Getsebool command are a set of tools that SELinux modifies and queries Boolean values.

Grammar

Setsebool [-P] Boolean value =[0|1]

Options

-P: Writes the setting value directly to the configuration file, which will take effect in the future.

Instance

Allow VSVTP Anonymous user write permission:

Setsebool-p allow_ftpd_anon_write=1

If you want your FTP user to be able to access your home directory, you need to turn on:

Setsebool-p Ftp_home_dir 1

If you want to run the vsftpd in a daemon way, you need to turn it on:

Setsebool-p Ftpd_is_daemon 1

You can let SELinux stop protecting VSFTPD's daemon way of moving the line:

Setsebool-p Ftpd_disable_trans 1

HTTP is set to allow CGI settings:

Setsebool-p httpd_enable_cgi 1

Allows users to access their home directory HHTP, which is limited to the user's home directory home page:

Setsebool-p Httpd_enable_homedirs 1

Chcon-r-T httpd_sys_content_t ~user/public_html

Allow httpd to access the terminal:

Setsebool-p Httpd_tty_comm 1

Turn off SELinux's protection for HTTPD process daemons:

Setsebool-p Httpd_disable_trans 1

Service httpd Restart

About named, Master updating SELinux settings:

Setsebool-p Named_write_master_zones 1

To turn off the process daemon protection for named:

Setsebool-p Named_disable_trans 1

Service named restart

SELinux sets the NFS share of this machine to read-only:

Setsebool-p Nfs_export_all_ro 1

SELinux sets the NFS share of this machine to be readable and writable:

Setsebool-p NFS_EXPORT_ALL_RW 1

If you want to share the remote NFS home directory to this machine, you need to turn on:

Setsebool-p Use_nfs_home_dirs 1

If the Samba server shares directories to multiple domains, you need to:

Setsebool-p allow_smbd_anon_write=1

When a samba server wants to share a home directory:

Setsebool-p Samba_enable_home_dirs 1

If you need to use the home directory of a remote samba server on this computer:

Setsebool-p Use_samba_home_dirs 1

Turn off SELinux protection for Samba's process daemon:

Setsebool-p Smbd_disable_trans 1

Service SMB Restart

Allow rsync other users to write:

Setsebool-p allow_rsync_anon_write=1

Stop Rsync's process protection

Setsebool-p Rsync_disable_trans 1

Allow the system to use Kerberos:

Setsebool-p Allow_kerberos 1

When the system is working in an NIS environment:

Setsebool-p Allow_ypbind 1


Semanage command

The Semanage command is used to query and modify the SELinux default directory's security context.

Grammar

semanage {login|user|port|interface|fcontext|translation}-L

Semanage fcontext-{a|d|m} [-frst] File_spec

Options

-L: Query.

Fcontext: Mainly used in the context of security.

-A: added, you can add default security context type settings for some directories.

-M: Modify.

-D: Delete.

Instance

Check the default security for/var/www/html settings for this article:

Semanage fcontext-lselinux fcontext Type Context

.... (omitted earlier) ....

/var/www (/.*)? All Files System_u:object_r:httpd_sys_content_t:s0

.... (omitted) ....

As shown in the example above, we can query the security of each directory to this article! The set of directories can use regular expressions to specify a range. So what if we want to increase the security of some custom directories this article? For example, what should I do if I want the color setting/srv/samba to be the type of public_content_t?

Set the default security for the/srv/samba directory with the semanage command this is public_content_t:

Mkdir/srv/samba

Ll-zd/srv/samba

Drwxr-xr-x root root Root:object_r:var_t/srv/samba

As shown above, the default situation should be var_t this!

Semanage Fcontext-l | grep '/srv '/srv/.* all Files System_u:object_r:var_t:s0

/srv/([^/]*/)? FTP (/.*)? All Files System_u:object_r:public_content_t:s0

/srv/([^/]*/)? www (/.*)? All Files System_u:object_r:httpd_sys_content_t:s0

/srv/([^/]*/)? Rsync (/.*)? All Files System_u:object_r:public_content_t:s0

/srv/gallery2 (/.*)? All Files System_u:object_r:httpd_sys_content_t:s0

/srv directory System_u:object_r:var_t:s0//Look here!

The above is the default/srv under the security document, however, is not specified to/srv/samba.

Semanage fcontext-a-T public_content_t "/srv/samba (/.*)?"

Semanage Fcontext-l |            grep '/srv/samba '/srv/samba (/.*)? All Files System_u:object_r:public_content_t:s0

Cat/etc/selinux/targeted/contexts/files/file_contexts.local

# This file was auto-generated by Libsemanage

# semanage command to make changes

/srv/samba (/.*)? System_u:object_r:public_content_t:s0 #写入这个档案

restorecon-rv/srv/samba* #尝试恢复默认值

Ll-zd/srv/samba

Drwxr-xr-x root root system_u:object_r:public_content_t/srv/samba/#有默认值, later with restorecon command to modify the easier!

The Semanage command has a lot of functions, the main use here is only the use of fcontext this option. As shown above, you can use Semanage to query all of the default values of the directory, and also to use it to increase the default settings!





SELinux policies related to rule management commands Seinfo, Sesearch, Getsebool, Setsebool, Semanage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.