Blame man7/credentials.7

Packit 7cfc04
.\" Copyright (c) 2007 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" 2007-06-13 Creation
Packit 7cfc04
.\"
Packit 7cfc04
.TH CREDENTIALS 7 2016-12-12 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
credentials \- process identifiers
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.SS Process ID (PID)
Packit 7cfc04
Each process has a unique nonnegative integer identifier
Packit 7cfc04
that is assigned when the process is created using
Packit 7cfc04
.BR fork (2).
Packit 7cfc04
A process can obtain its PID using
Packit 7cfc04
.BR getpid (2).
Packit 7cfc04
A PID is represented using the type
Packit 7cfc04
.I pid_t
Packit 7cfc04
(defined in
Packit 7cfc04
.IR <sys/types.h> ).
Packit 7cfc04
.PP
Packit 7cfc04
PIDs are used in a range of system calls to identify the process
Packit 7cfc04
affected by the call, for example:
Packit 7cfc04
.BR kill (2),
Packit 7cfc04
.BR ptrace (2),
Packit 7cfc04
.BR setpriority (2)
Packit 7cfc04
.\" .BR sched_rr_get_interval (2),
Packit 7cfc04
.\" .BR sched_getaffinity (2),
Packit 7cfc04
.\" .BR sched_setaffinity (2),
Packit 7cfc04
.\" .BR sched_getparam (2),
Packit 7cfc04
.\" .BR sched_setparam (2),
Packit 7cfc04
.\" .BR sched_setscheduler (2),
Packit 7cfc04
.\" .BR sched_getscheduler (2),
Packit 7cfc04
.BR setpgid (2),
Packit 7cfc04
.\" .BR getsid (2),
Packit 7cfc04
.BR setsid (2),
Packit 7cfc04
.BR sigqueue (3),
Packit 7cfc04
and
Packit 7cfc04
.BR waitpid (2).
Packit 7cfc04
.\" .BR waitid (2),
Packit 7cfc04
.\" .BR wait4 (2),
Packit 7cfc04
.PP
Packit 7cfc04
A process's PID is preserved across an
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.SS Parent process ID (PPID)
Packit 7cfc04
A process's parent process ID identifies the process that created
Packit 7cfc04
this process using
Packit 7cfc04
.BR fork (2).
Packit 7cfc04
A process can obtain its PPID using
Packit 7cfc04
.BR getppid (2).
Packit 7cfc04
A PPID is represented using the type
Packit 7cfc04
.IR pid_t .
Packit 7cfc04
.PP
Packit 7cfc04
A process's PPID is preserved across an
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.SS Process group ID and session ID
Packit 7cfc04
Each process has a session ID and a process group ID,
Packit 7cfc04
both represented using the type
Packit 7cfc04
.IR pid_t .
Packit 7cfc04
A process can obtain its session ID using
Packit 7cfc04
.BR getsid (2),
Packit 7cfc04
and its process group ID using
Packit 7cfc04
.BR getpgrp (2).
Packit 7cfc04
.PP
Packit 7cfc04
A child created by
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
inherits its parent's session ID and process group ID.
Packit 7cfc04
A process's session ID and process group ID are preserved across an
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.PP
Packit 7cfc04
Sessions and process groups are abstractions devised to support shell
Packit 7cfc04
job control.
Packit 7cfc04
A process group (sometimes called a "job") is a collection of
Packit 7cfc04
processes that share the same process group ID;
Packit 7cfc04
the shell creates a new process group for the process(es) used
Packit 7cfc04
to execute single command or pipeline (e.g., the two processes
Packit 7cfc04
created to execute the command "ls\ |\ wc" are placed in the
Packit 7cfc04
same process group).
Packit 7cfc04
A process's group membership can be set using
Packit 7cfc04
.BR setpgid (2).
Packit 7cfc04
The process whose process ID is the same as its process group ID is the
Packit 7cfc04
\fIprocess group leader\fP for that group.
Packit 7cfc04
.PP
Packit 7cfc04
A session is a collection of processes that share the same session ID.
Packit 7cfc04
All of the members of a process group also have the same session ID
Packit 7cfc04
(i.e., all of the members of a process group always belong to the
Packit 7cfc04
same session, so that sessions and process groups form a strict
Packit 7cfc04
two-level hierarchy of processes.)
Packit 7cfc04
A new session is created when a process calls
Packit 7cfc04
.BR setsid (2),
Packit 7cfc04
which creates a new session whose session ID is the same
Packit 7cfc04
as the PID of the process that called
Packit 7cfc04
.BR setsid (2).
Packit 7cfc04
The creator of the session is called the \fIsession leader\fP.
Packit 7cfc04
.PP
Packit 7cfc04
All of the processes in a session share a
Packit 7cfc04
.IR "controlling terminal" .
Packit 7cfc04
The controlling terminal is established when the session leader
Packit 7cfc04
first opens a terminal (unless the
Packit 7cfc04
.BR O_NOCTTY
Packit 7cfc04
flag is specified when calling
Packit 7cfc04
.BR open (2)).
Packit 7cfc04
A terminal may be the controlling terminal of at most one session.
Packit 7cfc04
.PP
Packit 7cfc04
At most one of the jobs in a session may be the
Packit 7cfc04
.IR "foreground job" ;
Packit 7cfc04
other jobs in the session are
Packit 7cfc04
.IR "background jobs" .
Packit 7cfc04
Only the foreground job may read from the terminal;
Packit 7cfc04
when a process in the background attempts to read from the terminal,
Packit 7cfc04
its process group is sent a
Packit 7cfc04
.BR SIGTTIN
Packit 7cfc04
signal, which suspends the job.
Packit 7cfc04
If the
Packit 7cfc04
.BR TOSTOP
Packit 7cfc04
flag has been set for the terminal (see
Packit 7cfc04
.BR termios (3)),
Packit 7cfc04
then only the foreground job may write to the terminal;
Packit 7cfc04
writes from background job cause a
Packit 7cfc04
.BR SIGTTOU
Packit 7cfc04
signal to be generated, which suspends the job.
Packit 7cfc04
When terminal keys that generate a signal (such as the
Packit 7cfc04
.I interrupt
Packit 7cfc04
key, normally control-C)
Packit 7cfc04
are pressed, the signal is sent to the processes in the foreground job.
Packit 7cfc04
.PP
Packit 7cfc04
Various system calls and library functions
Packit 7cfc04
may operate on all members of a process group,
Packit 7cfc04
including
Packit 7cfc04
.BR kill (2),
Packit 7cfc04
.BR killpg (3),
Packit 7cfc04
.BR getpriority (2),
Packit 7cfc04
.BR setpriority (2),
Packit 7cfc04
.BR ioprio_get (2),
Packit 7cfc04
.BR ioprio_set (2),
Packit 7cfc04
.BR waitid (2),
Packit 7cfc04
and
Packit 7cfc04
.BR waitpid (2).
Packit 7cfc04
See also the discussion of the
Packit 7cfc04
.BR F_GETOWN ,
Packit 7cfc04
.BR F_GETOWN_EX ,
Packit 7cfc04
.BR F_SETOWN ,
Packit 7cfc04
and
Packit 7cfc04
.BR F_SETOWN_EX
Packit 7cfc04
operations in
Packit 7cfc04
.BR fcntl (2).
Packit 7cfc04
.SS User and group identifiers
Packit 7cfc04
Each process has various associated user and group IDs.
Packit 7cfc04
These IDs are integers, respectively represented using the types
Packit 7cfc04
.I uid_t
Packit 7cfc04
and
Packit 7cfc04
.I gid_t
Packit 7cfc04
(defined in
Packit 7cfc04
.IR <sys/types.h> ).
Packit 7cfc04
.PP
Packit 7cfc04
On Linux, each process has the following user and group identifiers:
Packit 7cfc04
.IP * 3
Packit 7cfc04
Real user ID and real group ID.
Packit 7cfc04
These IDs determine who owns the process.
Packit 7cfc04
A process can obtain its real user (group) ID using
Packit 7cfc04
.BR getuid (2)
Packit 7cfc04
.RB ( getgid (2)).
Packit 7cfc04
.IP *
Packit 7cfc04
Effective user ID and effective group ID.
Packit 7cfc04
These IDs are used by the kernel to determine the permissions
Packit 7cfc04
that the process will have when accessing shared resources such
Packit 7cfc04
as message queues, shared memory, and semaphores.
Packit 7cfc04
On most UNIX systems, these IDs also determine the
Packit 7cfc04
permissions when accessing files.
Packit 7cfc04
However, Linux uses the filesystem IDs described below
Packit 7cfc04
for this task.
Packit 7cfc04
A process can obtain its effective user (group) ID using
Packit 7cfc04
.BR geteuid (2)
Packit 7cfc04
.RB ( getegid (2)).
Packit 7cfc04
.IP *
Packit 7cfc04
Saved set-user-ID and saved set-group-ID.
Packit 7cfc04
These IDs are used in set-user-ID and set-group-ID programs to save
Packit 7cfc04
a copy of the corresponding effective IDs that were set when
Packit 7cfc04
the program was executed (see
Packit 7cfc04
.BR execve (2)).
Packit 7cfc04
A set-user-ID program can assume and drop privileges by
Packit 7cfc04
switching its effective user ID back and forth between the values
Packit 7cfc04
in its real user ID and saved set-user-ID.
Packit 7cfc04
This switching is done via calls to
Packit 7cfc04
.BR seteuid (2),
Packit 7cfc04
.BR setreuid (2),
Packit 7cfc04
or
Packit 7cfc04
.BR setresuid (2).
Packit 7cfc04
A set-group-ID program performs the analogous tasks using
Packit 7cfc04
.BR setegid (2),
Packit 7cfc04
.BR setregid (2),
Packit 7cfc04
or
Packit 7cfc04
.BR setresgid (2).
Packit 7cfc04
A process can obtain its saved set-user-ID (set-group-ID) using
Packit 7cfc04
.BR getresuid (2)
Packit 7cfc04
.RB ( getresgid (2)).
Packit 7cfc04
.IP *
Packit 7cfc04
Filesystem user ID and filesystem group ID (Linux-specific).
Packit 7cfc04
These IDs, in conjunction with the supplementary group IDs described
Packit 7cfc04
below, are used to determine permissions for accessing files; see
Packit 7cfc04
.BR path_resolution (7)
Packit 7cfc04
for details.
Packit 7cfc04
Whenever a process's effective user (group) ID is changed,
Packit 7cfc04
the kernel also automatically changes the filesystem user (group) ID
Packit 7cfc04
to the same value.
Packit 7cfc04
Consequently, the filesystem IDs normally have the same values
Packit 7cfc04
as the corresponding effective ID, and the semantics for file-permission
Packit 7cfc04
checks are thus the same on Linux as on other UNIX systems.
Packit 7cfc04
The filesystem IDs can be made to differ from the effective IDs
Packit 7cfc04
by calling
Packit 7cfc04
.BR setfsuid (2)
Packit 7cfc04
and
Packit 7cfc04
.BR setfsgid (2).
Packit 7cfc04
.IP *
Packit 7cfc04
Supplementary group IDs.
Packit 7cfc04
This is a set of additional group IDs that are used for permission
Packit 7cfc04
checks when accessing files and other shared resources.
Packit 7cfc04
On Linux kernels before 2.6.4,
Packit 7cfc04
a process can be a member of up to 32 supplementary groups;
Packit 7cfc04
since kernel 2.6.4,
Packit 7cfc04
a process can be a member of up to 65536 supplementary groups.
Packit 7cfc04
The call
Packit 7cfc04
.I sysconf(_SC_NGROUPS_MAX)
Packit 7cfc04
can be used to determine the number of supplementary groups
Packit 7cfc04
of which a process may be a member.
Packit 7cfc04
.\" Since kernel 2.6.4, the limit is visible via the read-only file
Packit 7cfc04
.\" /proc/sys/kernel/ngroups_max.
Packit 7cfc04
.\" As at 2.6.22-rc2, this file is still read-only.
Packit 7cfc04
A process can obtain its set of supplementary group IDs using
Packit 7cfc04
.BR getgroups (2),
Packit 7cfc04
and can modify the set using
Packit 7cfc04
.BR setgroups (2).
Packit 7cfc04
.PP
Packit 7cfc04
A child process created by
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
inherits copies of its parent's user and groups IDs.
Packit 7cfc04
During an
Packit 7cfc04
.BR execve (2),
Packit 7cfc04
a process's real user and group ID and supplementary
Packit 7cfc04
group IDs are preserved;
Packit 7cfc04
the effective and saved set IDs may be changed, as described in
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.PP
Packit 7cfc04
Aside from the purposes noted above,
Packit 7cfc04
a process's user IDs are also employed in a number of other contexts:
Packit 7cfc04
.IP * 3
Packit 7cfc04
when determining the permissions for sending signals (see
Packit 7cfc04
.BR kill (2));
Packit 7cfc04
.IP *
Packit 7cfc04
when determining the permissions for setting
Packit 7cfc04
process-scheduling parameters (nice value, real time
Packit 7cfc04
scheduling policy and priority, CPU affinity, I/O priority) using
Packit 7cfc04
.BR setpriority (2),
Packit 7cfc04
.BR sched_setaffinity (2),
Packit 7cfc04
.BR sched_setscheduler (2),
Packit 7cfc04
.BR sched_setparam (2),
Packit 7cfc04
.BR sched_setattr (2),
Packit 7cfc04
and
Packit 7cfc04
.BR ioprio_set (2);
Packit 7cfc04
.IP *
Packit 7cfc04
when checking resource limits (see
Packit 7cfc04
.BR getrlimit (2));
Packit 7cfc04
.IP *
Packit 7cfc04
when checking the limit on the number of inotify instances
Packit 7cfc04
that the process may create (see
Packit 7cfc04
.BR inotify (7)).
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
Process IDs, parent process IDs, process group IDs, and session IDs
Packit 7cfc04
are specified in POSIX.1.
Packit 7cfc04
The real, effective, and saved set user and groups IDs,
Packit 7cfc04
and the supplementary group IDs, are specified in POSIX.1.
Packit 7cfc04
The filesystem user and group IDs are a Linux extension.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The POSIX threads specification requires that
Packit 7cfc04
credentials are shared by all of the threads in a process.
Packit 7cfc04
However, at the kernel level, Linux maintains separate user and group
Packit 7cfc04
credentials for each thread.
Packit 7cfc04
The NPTL threading implementation does some work to ensure
Packit 7cfc04
that any change to user or group credentials
Packit 7cfc04
(e.g., calls to
Packit 7cfc04
.BR setuid (2),
Packit 7cfc04
.BR setresuid (2))
Packit 7cfc04
is carried through to all of the POSIX threads in a process.
Packit 7cfc04
See
Packit 7cfc04
.BR nptl (7)
Packit 7cfc04
for further details.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR bash (1),
Packit 7cfc04
.BR csh (1),
Packit 7cfc04
.BR groups (1),
Packit 7cfc04
.BR id (1),
Packit 7cfc04
.BR newgrp (1),
Packit 7cfc04
.BR ps (1),
Packit 7cfc04
.BR runuser (1),
Packit 7cfc04
.BR setpriv (1),
Packit 7cfc04
.BR sg (1),
Packit 7cfc04
.BR su (1),
Packit 7cfc04
.BR access (2),
Packit 7cfc04
.BR execve (2),
Packit 7cfc04
.BR faccessat (2),
Packit 7cfc04
.BR fork (2),
Packit 7cfc04
.BR getgroups (2),
Packit 7cfc04
.BR getpgrp (2),
Packit 7cfc04
.BR getpid (2),
Packit 7cfc04
.BR getppid (2),
Packit 7cfc04
.BR getsid (2),
Packit 7cfc04
.BR kill (2),
Packit 7cfc04
.BR setegid (2),
Packit 7cfc04
.BR seteuid (2),
Packit 7cfc04
.BR setfsgid (2),
Packit 7cfc04
.BR setfsuid (2),
Packit 7cfc04
.BR setgid (2),
Packit 7cfc04
.BR setgroups (2),
Packit 7cfc04
.BR setpgid (2),
Packit 7cfc04
.BR setresgid (2),
Packit 7cfc04
.BR setresuid (2),
Packit 7cfc04
.BR setsid (2),
Packit 7cfc04
.BR setuid (2),
Packit 7cfc04
.BR waitpid (2),
Packit 7cfc04
.BR euidaccess (3),
Packit 7cfc04
.BR initgroups (3),
Packit 7cfc04
.BR killpg (3),
Packit 7cfc04
.BR tcgetpgrp (3),
Packit 7cfc04
.BR tcsetpgrp (3),
Packit 7cfc04
.BR group (5),
Packit 7cfc04
.BR passwd (5),
Packit 7cfc04
.BR shadow (5),
Packit 7cfc04
.BR capabilities (7),
Packit 7cfc04
.BR namespaces (7),
Packit 7cfc04
.BR path_resolution (7),
Packit 7cfc04
.BR pid_namespaces (7),
Packit 7cfc04
.BR pthreads (7),
Packit 7cfc04
.BR signal (7),
Packit 7cfc04
.BR unix (7),
Packit 7cfc04
.BR user_namespaces (7),
Packit 7cfc04
.BR sudo (8)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.