---
source: https://iinventedlight.com/library/notes/go-os-user.md
title: "Go os/user: look up accounts by name or id"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, os/user package reference; Go, os/user source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-os-user"
tags: [go, os, user, group, passwd]
client: Librarian
sources:
  - id: S1
    title: "os/user package reference"
    publisher: Go
    url: https://pkg.go.dev/os/user
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "os/user source"
    publisher: Go
    url: https://go.dev/src/os/user/user.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
---
# Go os/user: look up accounts by name or id
**Answer:** Package user allows user account lookups by name or id. On most Unix systems there are two internal implementations. One is written in pure Go and parses /etc/passwd and /etc/group.

## Lookups in the package reference

The package allows user account lookups by name or id.

Current, Lookup, and LookupId return a User. GroupIds returns supplementary group IDs.

Most Unix systems have two internal implementations of resolving user and group ids to names.

One path is written in pure Go and parses /etc/passwd and /etc/group.

## Pure Go versus cgo in the source

The source comment also allows user account lookups by name or id.

The other path is cgo-based and relies on the standard C library, libc, with routines such as getpwuid_r.

When cgo is available and the required routines are implemented in libc, that cgo-based code is used.

The osusergo build tag can override this and enforce the pure Go implementation.

## See also

- [go-os-exec](https://iinventedlight.com/library/notes/go-os-exec/)
- [go-os-signal](https://iinventedlight.com/library/notes/go-os-signal/)
- [go-net-dial-listen](https://iinventedlight.com/library/notes/go-net-dial-listen/)

## Claims

- id: C1
  claim: The package allows user account lookups by name or id.
  source: S1
  evidence: "user account lookups by name or id"

- id: C2
  claim: The pure Go path parses passwd and group files.
  source: S1
  evidence: "parses /etc/passwd and /etc/group"

- id: C3
  claim: The source comment allows user account lookups by name or id.
  source: S2
  evidence: "Package user allows user account lookups by name or id."

- id: C4
  claim: The other path is cgo-based and relies on the standard C library.
  source: S2
  evidence: "cgo-based and relies on the standard C library"

## Sources

- [S1] os/user package reference. Go. https://pkg.go.dev/os/user . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] os/user source. Go. https://go.dev/src/os/user/user.go . License: BSD-3-Clause. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, os/user package reference; Go, os/user source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
