GPG-CONNECT-AGENT(1)
okay so real talk: this is gpg-connect-agent(1) from GNU Privacy Guard 2.4 β yes, that GnuPG, the one your crypto-nerd friend keeps telling you about π
β and it's genuinely one of the most useful little tools in the whole suite. Buckle up bestie π
πΈ NAME πΈ
gpg-connect-agent β the way to Communicate with a running agent. That's it. That's the whole vibe. π«Ά
β¨ SYNOPSIS β¨
gpg-connect-agent [options][commands]
(yes, [options][commands] is written all squished together like that, no space β iconic, don't touch it π)
π¦ DESCRIPTION π¦
Okay so picture this: gpg-connect-agent is a utility to communicate with a running gpg-agent. That's the whole main character energy right there π
It's genuinely useful for checking out all the commands gpg-agent provides using the Assuan interface β like, you can literally poke at the agent and see what it's made of. It might also be useful for scripting simple applications (key word simple, goblins, don't go building your whole startup on this π).
The flow is: input is expected at stdin, and output gets printed to stdout. Clean, classic, no notes. β¨
It's very similar to running gpg-agent in server mode β except here we connect to a running instance. That distinction is lowkey the whole point, iykyk.
The following options may be used:
π THE OPTIONS π
--dirmngrβ Connect to a running directory manager (keyserver client) instead of to thegpg-agent. And if a dirmngr is not running? It just starts it. Problem solved, slay. β¨--keyboxdβ Connect to a running keybox daemon instead of to thegpg-agent. If a keyboxd is not running, it starts it. Same energy, different daemon π-S,--raw-socketname β Connect to socket name assuming this is an Assuan style server. Do not run any special initializations or environment checks β it goes straight in, no vibe check, no small talk. This may be used to directly connect to any Assuan style socket server. Raw, unfiltered, main character π¦-E,--execβ Take the rest of the command line as a program and it's arguments and execute it as an Assuan server. Here's how you would rungpgsm:
gpg-connect-agent --exec gpgsm --server
β οΈ Note that you may not use options on the command line in this case. Because the rest of the command line is the program now, bestie. It's taken. It's booked. π
-v,--verboseβ Output additional information while running. For when you wanna know everything that's happening π-q,--quietβ Try to be as quiet as possible. For when you wanna know nothing π€«--homedirdir β Set the name of the home directory to dir. If this option is not used, the home directory defaults to~/.gnupg. Important detail: it is only recognized when given on the command line. It also overrides any home directory stated through the environment variableGNUPGHOMEor (on Windows systems) by means of the Registry entryHKCU\Software\GNU\GnuPG:HomeDir. π
On Windows systems it is possible to install GnuPG as a portable application. In this case only this command line option is considered β all other ways to set a home directory are ignored. Periodt. π
--chuiduid β Change the current user to uid, which may either be a number or a name. This can be used from the root account to rungpg-connect-agentfor another user. If uid is not the current UID, a standardPATHis set and the envvarGNUPGHOMEis unset β and to override the latter, the option--homedircan be used. This option has only an effect when used on the command line. And heads up: this option has currently no effect at all on Windows. π«--no-ext-connectβ When using-Sor--exec,gpg-connect-agentconnects to the Assuan server in extended mode to allow descriptor passing. This option makes it use the old mode instead. Retro vibes, but make it intentional π--no-autostartβ Do not start thegpg-agentor thedirmngrif it has not yet been started. You're on your own, babe π--no-historyβ In interactive mode the command line history is usually saved and restored to and from a file below the GnuPG home directory. This option inhibits the use of that file. No receipts, no trail π--agent-programfile β Specify the agent program to be started if none is running. The default value is determined by runninggpgconfwith the option--list-dirs.
β οΈ Real caveat: note that the pipe symbol (|) is used for a regression test suite hack and may thus not be used in the file name. Do not fight this, it's not worth it π
--dirmngr-programfile β Specify the directory manager (keyserver client) program to be started if none is running. This has only an effect if used together with the option--dirmngr. Teamwork, bestie π«Ά--keyboxd-programfile β Specify the keybox daemon program to be started if none is running. This has only an effect if used together with the option--keyboxd. Same deal, different daemon β¨-rfile,--runfile β Run the commands from file at startup and then continue with the regular input method. Note, that commands given on the command line are executed after this file. Order matters, always π₯-s,--substβ Run the command/substat startup. That's literally the whole thing. Short, sweet, iconic π--hexβ Print data lines in a hex format and the ASCII representation of non-control characters. For my hex girlies π’--decodeβ Decode data lines. That is to remove percent escapes but make sure that a new line always starts with aDand a space. Yes, theDand the space are non-negotiable π-u,--unbufferedβ Set stdin and stdout into unbuffered I/O mode. This is sometimes useful for scripting. When you need it, you know πΈ
π CONTROL COMMANDS π
So while gpg-agent is out here reading Assuan commands, it also lets you slide in a few special commands to control the whole operation. These control commands all start with a slash (/). Periodt. π
/echo argsβ literally just prints args back at you. That's it. That's the whole job. Iconic minimalism. β¨/let name valueβ sets the variable name to value. Okay so important tea: variables are only substituted on the input if you've used/subst. You reference a variable by putting a dollar sign in front of the name, and you can optionally wrap the name in curly braces. The rules for what counts as a valid name are identical to those of the standard bourne shell β tho ngl, that's not yet enforced, but it may be in the future, so don't get too comfy. π When you use curly braces, no leading or trailing white space is allowed.
If a variable isn't found, it gets searched in the environment, and if it's found there it gets copied over to the table of variables. Sneaky but slay. π¦
Variable functions exist too! The name of the function must be followed by at least one space and at least one argument. Here's the lineup:
get β returns a value described by the argument. Available arguments are:
cwdβ the current working directory.homedirβ the gnupg homedir.sysconfdirβ GnuPG's system configuration directory.bindirβ GnuPG's binary directory.libdirβ GnuPG's library directory.libexecdirβ GnuPG's library directory for executable files.datadirβ GnuPG's data directory.serverpidβ the PID of the current server. Heads up tho: the command/serverpidmust have been given for this to return a useful value. No/serverpid, no useful vibe check. π
unescape args β removes C-style escapes from args. Note that \0 and \x00 terminate the returned string implicitly. The string being converted is the entire arguments right behind the delimiting space of the function name. π§
unpercent args / unpercent+ args β removes percent style escaping from args. Note that %00 terminates the string implicitly. The string being converted is the entire arguments right behind the delimiting space of the function name. unpercent+ also maps plus signs to spaces. Extra. π
percent args / percent+ args β escapes args using percent style escaping. Tabs, formfeeds, linefeeds, carriage returns and colons are escaped. percent+ also maps spaces to plus signs. πΈ
errcode arg / errsource arg / errstring arg β assume arg is an integer and evaluate it using strtol. Returns the gpg-error error code, the error source, or a formatted string with the error code and error source. π
+ / - / * / / / % β evaluate all arguments as long integers using strtol, then apply this operator. A division by zero yields an empty string (so like, no crash, just vibes). π₯
! / | / & β evaluate all arguments as long integers using strtol, then apply the logical operators NOT, OR or AND. The NOT operator works on the last argument only. Main character energy tbh. π
/definq name varβ uses the content of the variable var for inquiries with name. And name may be an asterisk (*) to match any inquiry. Wildcard queen. β/definqfile name fileβ uses the content of file for inquiries with name. Again, name may be an asterisk (*) to match any inquiry./definqprog name progβ runs prog for inquiries matching name, and passes the entire line to it as command line arguments. π«Ά/datafile nameβ writes all data lines from the server to the file name. The file is opened for writing and created if it doesn't exist. An existing file is first truncated to0. The data written to the file is fully decoded. Using a single dash for name writes to stdout. The file is kept open until a new file is set using this command, or until this command is used without an argument. π (rip your previous file, fr fr)/showdefβ prints all definitions./cleardefβ deletes all definitions. Clean slate, fresh start, new era. β¨/sendfd file modeβ opens file in mode (which needs to be a validfopenmode string) and sends the file descriptor to the server. This is usually followed by a command likeINPUT FDto set the input source for other commands. π¦/recvfdβ not yet implemented. She's coming, bestie. Not yet, but she's coming. π/open var file [mode]β opens file and assigns the file descriptor to var. > Warning: this command is experimental and might change in future versions. Handle with care! π/close fdβ closes the file descriptor fd. > Warning: this command is experimental and might change in future versions. Same energy. π/showopenβ shows a list of open files. Peek behind the curtain. π/serverpidβ sends the Assuan commandGETINFO pidto the server and stores the returned PID for internal purposes. (Remember this one β/let'sget serverpidneeds it!) π/sleepβ sleeps for a second. Take a lil nap. Self care. π΄/hex//nohexβ same as the command line option--hex. β/decode//nodecodeβ same as the command line option--decode. π/subst//nosubstβ enable and disable variable substitution. It defaults to disabled unless the command line option--substhas been used. And here's a cute detail: if/substhas been enabled once, leading whitespace is removed from input lines, which makes scripts easier to read. You're welcome. π/while condition//endβ these commands give you a way to execute loops! All lines between thewhileand the correspondingendare executed as long as the evaluation of condition yields a non-zero value, or is the stringtrueoryes. The evaluation is done by passing condition to thestrtolfunction. Example time, bestie:
/subst
/let i 3
/while $i
/echo loop counter is $i
/let i ${- $i 1}
/end
Countdown loop, ate. π₯
/if condition//endβ these commands give you conditional execution. All lines between theifand the correspondingendare executed only if the evaluation of condition yields a non-zero value, or is the stringtrueoryes. The evaluation is done by passing condition to thestrtolfunction. Same rules, different drama. π/run fileβ runs commands from file. Script girlie behavior. π/history --clearβ clears the command history. No receipts, no evidence, we don't know her. π/byeβ terminates the connection and the program. The exit. The farewell. The mic drop. π/helpβ prints a list of available control commands. When in doubt, ask for help β that's growth. π«Ά
πΈ SEE ALSO πΈ
The full documentation for this tool is maintained as a Texinfo manual. If GnuPG and the info program are properly installed at your site, the command
info gnupg
should give you access to the complete manual including a menu structure and an index. Go read it, it's giving comprehensive. πβ¨
And that's the whole page, bestie! π This lil masterpiece is from GnuPG 2.4.9, dated 2025-02-19 β icon behavior, no notes. π ππ
π¦ where this page comes from
- alpine 3.22: gnupg-doc 2.4.9-r0 Β· GPL-3.0-or-later
- alpine 3.23: gnupg-doc 2.4.9-r0 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms