Skip to Content
SELinux Cookbook
book

SELinux Cookbook

by Sven Vermeulen
September 2014
Intermediate to advanced
240 pages
5h 53m
English
Packt Publishing
Content preview from SELinux Cookbook

Switching roles

When a role transition is needed for more than just a couple of commands, it is necessary to open a shell with the new role. This will ensure that the entire session is now running with the new role assigned to it. Every activity performed from within this session will then run with the target role.

How to do it…

Switching roles with sudo or newrole is done as follows:

  1. Switching a role can be done using sudo -i or sudo -s if allowed by the sudoers file. If the ROLE and TYPE attributes are set, then the target shell will have the proper context assigned:
    ~$ id -Z
    dbadm_u:staff_r:staff_t:s0
    ~$ sudo -u postgres -i
    Password: 
    ~$ id -Z
    dbadm_u:dbadm_r:dbadm_t:s0
    
  2. Switching roles can also be done using newrole:
    ~$ newrole -r dbadm_r
    

How ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SELinux

SELinux

Bill McCarty
SELinux by Example: Using Security Enhanced Linux

SELinux by Example: Using Security Enhanced Linux

Frank Mayer, Karl MacMillan, David Caplan
CentOS Quick Start Guide

CentOS Quick Start Guide

Shiwang Kalkhanda

Publisher Resources

ISBN: 9781783989669Supplemental Content