User session

Also known as: login session

On this page 8

A user session, also called a login session, is the bounded period during which an authenticated person interacts with an operating system, together with the kernel and system objects that represent that interaction: an access token or credential set, a desktop or terminal, environment settings and every process started on the person’s behalf. In operating systems, the session is the unit that connects user accounts to running work, which is why it matters for security, resource accounting and clean sign out.

A session begins when authentication succeeds at the login screen, through a remote protocol or by automatic login, and it ends when the person signs out, the system shuts down or an administrator terminates it. Between those two points, the operating system isolates one session from another so that several people, or several service identities, can share one machine without seeing or controlling each other’s programs.

How an operating system creates a user session

Session creation is a chain of privileged steps that turns verified credentials into a working environment. A trusted login component collects the credentials, an authentication service validates them against a local database or a directory, and the system then builds a security context that every later process inherits.

  1. The login manager (Winlogon with LogonUI on Windows, loginwindow on macOS, a display manager such as GDM or a getty and login pair on Linux) presents the prompt.
  2. An authentication subsystem such as LSASS, Open Directory or PAM checks the password, smart card, biometric or Kerberos ticket.
  3. The system assigns a session identifier and creates the access token, credential structure or audit session that carries the user identity and group memberships.
  4. The user profile and home directory are loaded, environment variables are set and startup programs run.
  5. The shell or desktop environment starts as the first interactive process, and all child processes inherit the session.

Because each process carries the session identity, the kernel can enforce access control on files, registry keys, devices and inter-process communication without asking the user again. The same mechanism lets the system find and close every process in a session when it ends.

Session types and their properties

Operating systems distinguish several kinds of sessions, and the differences decide what a session may display, which devices it owns and how long it lives. The table below compares the most common types.

Session typeHow it startsTypical traits
Interactive consoleSign-in at the local login screenOwns physical keyboard, display and audio
Remote graphicalRDP, VNC or similar protocolVirtual display, redirected devices
Remote terminalSSH or serial consoleText only, no desktop by default
Service or batchService manager or schedulerNo user interface, runs under a system account
DisconnectedRemote client drops or user locks outProcesses keep running without a display
Common types of user sessions

On Windows, session 0 isolation reserves session 0 for services since Windows Vista, while interactive users receive session 1 and higher. This separation blocks shatter attacks, in which a low-privilege program sends window messages to a privileged service sharing the same desktop.

How major platforms track sessions

Each platform implements sessions with its own components, yet the underlying model is the same: a session identifier, a security context and a process tree. The following comparison names the parts an administrator meets in practice.

PlatformSession trackerIdentity carrierInspection command
WindowsSession Manager and Terminal ServicesAccess token with logon SIDquery session, qwinsta
macOSloginwindow and launchdAudit session and per-user launchd domainwho, launchctl print
Linuxsystemd-logindUID, GID list and session scopeloginctl list-sessions
Traditional Unixutmp and wtmp recordsUID and controlling terminalwho, last
Session components by platform

On Linux, systemd-logind places each session in its own control group, which allows the system to account CPU and memory per session and to kill lingering processes at sign out when the KillUserProcesses option is enabled. On Windows, the logon SID inside the token lets the system grant access to the window station and desktop of exactly one session.

A user session is often confused with neighboring ideas in the same topic, but each describes a different layer. The account is the identity, the profile is stored data and the session is the live runtime instance of that identity.

ConceptWhat it representsLifetime
User accountIdentity, credentials and group membershipsUntil deleted
User profileSettings, documents and application dataPersistent on disk
User sessionRunning context with token and processesSign-in to sign out
Web sessionServer-side state tied to a cookieUntil timeout or logout
How a session differs from related terms

Fast user switching depends on this distinction: it keeps the first session alive and disconnected while a second user signs in, so two sessions coexist on one machine. A multi-user system generalizes the same idea to many simultaneous local and remote sessions.

Managing session lifetime and security

Administrators control sessions through lock, timeout and termination policies, and the right choice balances convenience against exposure. A locked session keeps programs running but requires authentication to resume, whereas signing out destroys the session and releases its resources.

SituationRecommended controlReason
Shared office workstationScreen lock after 5-15 minutesLimits access by passers-by
Remote desktop serverDisconnected session limitFrees memory and licenses
Kiosk or public terminalSign out on idleRemoves the previous user’s data
Privileged administrationSeparate elevated sessionKeeps admin rights short-lived
Session controls and when to apply them

Session security also depends on how credentials are held. On Windows, cached credentials in LSASS memory can be stolen while a session is active, which is why Credential Guard and short-lived administrator sessions reduce the risk of credential theft and lateral movement.

Common mistakes and failure modes

Most session problems arise from assuming a session ends when it has not, or from mixing contexts. Experienced administrators watch for the following issues.

  • Orphaned processes that survive sign out and keep files locked or consume memory.
  • Disconnected remote sessions that remain logged in for days and hold privileged tokens.
  • Services that try to show a dialog in session 0, which the interactive user never sees.
  • Group membership changes that do not apply until a new session begins, because the token is built at sign-in.
  • Shared accounts that make it impossible to attribute session activity to one person in audit logs.

In plain words

A user session is the time you spend signed in to a computer, plus everything the computer keeps track of while you are there. When you sign in, the system gives you a kind of visitor badge that every program you open carries with it. That badge says who you are and what you are allowed to touch.

When you sign out, the badge is taken back and your programs are closed. Locking the screen is different: your programs keep running and wait for you to come back. Several people can each have their own session on one computer, and the system keeps them apart.

A real-world example

A small accounting firm runs a Windows remote desktop server for 20 employees. Staff often close the remote window instead of signing out, so their sessions stay disconnected but alive, each holding an open spreadsheet and about 400 MB of memory. By Friday the server has more than 30 lingering sessions and becomes slow, and several shared workbooks stay locked.

The administrator uses query session to list the disconnected sessions, then sets a policy that ends disconnected sessions after two hours and idle active sessions after eight hours. The administrator also adds a nightly report of sessions held by administrator accounts. Within a week, memory use drops by roughly a third, locked-file complaints stop and no privileged session remains open overnight.