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
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.
License: CC-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.
Cite this
iinventedlight. 2026. "Go os/user: look up accounts by name or id." iinventedlight Library, iil:note:85pp7aa1, version of 2026-11-23. https://iinventedlight.com/library/notes/go-os-user/. License: CC-BY-4.0.
@misc{iil_note_85pp7aa1,
author = {{iinventedlight}},
title = {{Go os/user: look up accounts by name or id}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-os-user/},
note = {Permanent ID iil:note:85pp7aa1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-os-user.schema.json (schema; CC-BY-4.0)
- go-os-user.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-os-user.md.