← All notes

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

Sources

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

Permanent ID: iil:note:85pp7aa1

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.},
}

Markdown

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.

All artifact files (JSON index)

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.