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/tty again

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/tty cannot be opened, the prompt is written to stderr and the password is read from stdin. 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_MAX must be defined in <limits.h> in case it is smaller than 8, and can in any case be obtained using sysconf(_SC_PASS_MAX). However, POSIX.2 withdraws the constants PASS_MAX and _SC_PASS_MAX, and the function getpass(). The glibc version accepts _SC_PASS_MAX and returns BUFSIZ (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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms