getpass(3)
๐ getpass(3) โ the "get a password" function, Library Functions Manual ๐
okay bestie, sit down, because we're about to talk about getpass, an icon of the Library Functions Manual who is, and I cannot stress this enough, fully obsolete. She's giving vintage. She's giving "please do not." Let's get into it ๐
โจ NAME โจ
getpass โ get a password ๐๐
๐ธ LIBRARY ๐ธ
Standard C library (libc, -lc)
๐ฆ SYNOPSIS ๐ฆ
#include <unistd.h>
[[deprecated]] char *getpass(const char *prompt);
๐ง Feature Test Macro Requirements for glibc
(go peek at feature_test_macros(7) if you need the lore)
getpass():
Since glibc 2.2.2:
_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
|| /* glibc >= 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _BSD_SOURCE
Before glibc 2.2.2:
none
๐ DESCRIPTION ๐
Okay so. This function is obsolete. Do not use it. Not even being dramatic, that's literally what the docs say. Go read NOTES below, I promise it's worth it. And if what you actually want is to read input with terminal echoing turned off, go look at the description of the ECHO flag in termios(3type) instead, bestie, that's the move ๐ซถ
So what does getpass() even do? It:
- opens
/dev/tty(that's the controlling terminal of the process, the way your program's terminal-y home base) ๐ - outputs the string
prompt - turns off echoing (so nobody sees you typing, iconic)
- reads one line โ the "<password>" if you will โจ
- restores the terminal state
- and closes
/dev/ttyagain
that's the whole routine. periodt.
๐ RETURN VALUE ๐
getpass() hands you back a pointer to a static buffer. Inside that buffer is (the first PASS_MAX bytes of) the password, with the trailing newline yeeted, and it's terminated by a null byte ('\0').
โ ๏ธ Heads up: that buffer may be overwritten by a following call. It's one buffer, shared, reused. So don't get attached, and definitely don't hold onto the pointer thinking it's yours ๐
On error? The terminal state gets restored, errno is set to indicate the error, and NULL is returned. Balance restored, but at what cost ๐ญ
๐ ERRORS ๐
ENXIOโ the process does not have a controlling terminal. no tty, no vibes, no password ๐ซ
๐ FILES ๐
/dev/tty
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
getpass()โ Thread safety: MT-Unsafe term ๐งต๐จ
(it was a table in the original bestie, but tables are not the vibe here, so: one interface, one attribute, one value. that's the whole thing.)
โญ STANDARDS โญ
None. ๐ literally none. she's not standardized, she's not claiming to be, she's just out here.
๐ธ HISTORY ๐ธ
- Version 7 AT&T UNIX ๐ฆ
- Present in SUSv2, but marked LEGACY
- Removed in POSIX.1-2001 ๐ชฆ
so yeah, she's been around, and she's been shown the door.
๐ NOTES ๐
okay this is the part where we get real:
- You should use instead
readpassphrase(3bsd), provided by libbsd. that's the upgrade, that's the main character, that's who you should be calling ๐ - In the GNU C library implementation, if
/dev/ttycannot be opened, thepromptis written tostderrand the password is read fromstdin. And ngl: there is no limit on the length of the password, and line editing is not disabled ๐ - According to SUSv2, the value of
PASS_MAXmust be defined in<limits.h>in case it is smaller than 8, and can in any case be obtained usingsysconf(_SC_PASS_MAX). However, POSIX.2 withdraws the constantsPASS_MAXand_SC_PASS_MAX, and the functiongetpass(). The glibc version accepts_SC_PASS_MAXand returnsBUFSIZ(e.g.,8192). yes, the lore is messy, we don't make the rules ๐ญ
๐ญ BUGS ๐ญ
The calling process should zero the password as soon as possible to avoid leaving the cleartext password visible in the process's address space. Like, immediately bestie. Don't leave the cleartext just sitting there in memory, that's not the vibe, that's a whole security situation ๐ฅ๐จ
๐ซถ SEE ALSO ๐ซถ
and that's the tea ๐
this lil rewrite was brought to you by Linux man-pages 6.20, dated 2026-07-02, from the getpass(3) page itself โ stay safe, use readpassphrase(3bsd), and zero your buffers, ily ๐โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- Copyright 2000, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms