getcontext - Linux


getcontext displays the system security context of the current process. It provides detailed information about the security attributes, such as user ID, group ID, and access control lists (ACLs), associated with the process. This command is essential for understanding and managing security contexts in Linux systems.


getcontext [OPTIONS]


  • -a, –audit: Display audit context.
  • -c, –cred: Display credentials context.
  • -e, –entitlements: Display entitlement context.
  • -f, –format=: Specify output format. Options include "pretty" (default), "raw", and "json".
  • -h, –help: Display help information.
  • -m, –mode=: Display specific mode of context. Valid options include "username" (default), "numeric", "hexadecimal", and "unix".
  • -r, –capability-raw: Display raw capability bits.
  • -p, –pid=: Display context of a specific process.


  • Display the default system security context in "pretty" format:
  • Display the numeric user ID and group ID using the "-m unix" option:
getcontext -m unix
  • Display the raw capability bits in hexadecimal format:
getcontext -r -m hexadecimal
  • Retrieve the security context of a specific process (PID 1024):
getcontext -p 1024

Common Issues

  • Permission denied: Ensure you have sufficient privileges to read the security context of the target process.
  • Invalid PID: Verify that the specified PID is valid and refers to an existing process.
  • Unknown format: Specify a valid output format when using the "-f" option.


getcontext can be used in conjunction with other Linux commands for advanced security analysis and management tasks:

  • ps -eZ: Display process status with security context.
  • sudo getcontext -a: Check the audit context of commands executed with elevated privileges.
  • grep -E ‘user=(.) group=(.)’ : Extract user and group information from getcontext output.

Related Commands