gen-key non-interactively

snowcrash+gnupg-users schneecrash+gnupg-users at
Thu Feb 8 16:44:02 CET 2007

here's an "expect"-based function i use in a bash script for just such purpose,

# function: "DO_GENKEY_SESSION"
	# auto-execute a GPG --gen-key session
	# usage:
	# gen-key dialog options (SELECTION):
	# Please select what kind of key you want:
	#   (1) DSA and Elgamal (default)
	#   (2) DSA (sign only)
	#   (3) DSA (set your own capabilities)
	#   (5) RSA (sign only)
	#   (7) RSA (set your own capabilities)
	VAR=$($EXPECT -c "
		spawn  $GPG $GPG_RING_OPTS --expert --cert-notation $NOTATION --gen-key
		set timeout -1
		stty -echo
		expect     \"Your selection? \"
		exp_send   \"$1\n\"
		expect -re \"(What keysize do you want\?).*\\\\(\[0-9\]*\\\\) \"
		exp_send   \"$BITS\n\"
		expect     \"Key is valid for? (0) \"
		exp_send   \"0\n\"
		expect     \"Is this correct? (y/N) \"
		exp_send   \"y\n\"
		expect     \"Real name: \"
		exp_send   \"$NAME_REAL\n\"
		expect     \"Email address: \"
		exp_send   \"$EMAIL\n\"
		expect     \"Comment: \"
		exp_send   \"$SIG_COMMENT\n\"
		expect     \"(O)kay/(Q)uit? \"
		exp_send   \"O\n\"
		expect     \"Enter passphrase: \"
		exp_send   \"$PASS\n\"
		expect     \"Repeat passphrase: \"
		exp_send   \"$PASS\n\"
		expect exp_continue -continue_timer
	echo "   DONE"

of course, you define/pass/replace the various vars as you need/like ...


More information about the Gnupg-users mailing list