It's not very clear how to fetch the pubkey. OK to add this to wg(4)?
Index: wg.4
===================================================================
RCS file: /cvs/src/share/man/man4/wg.4,v
retrieving revision 1.6
diff -u -p -r1.6 wg.4
--- wg.4 24 Nov 2020 16:33:05 -0000 1.6
+++ wg.4 27 Nov 2020 12:28:32 -0000
@@ -64,6 +64,9 @@ interface may be configured to recognise
.It Key
Each peer uses its private key and corresponding public key to
identify itself to others.
+The public key may be displayed by running
+.Xr ifconfig 8
+as root after configuring the private key.
A peer configures a
.Nm wg
interface with its own private key and with the public keys of its peers.
@@ -138,9 +141,11 @@ but demonstrates two interfaces on the s
.Bd -literal
#!/bin/sh
+# create interfaces, set random private keys
ifconfig wg1 create wgport 7111 wgkey `openssl rand -base64 32` rdomain 1
ifconfig wg2 create wgport 7222 wgkey `openssl rand -base64 32` rdomain 2
+# retrieve the public keys associated with the private keys
PUB1="`ifconfig wg1 | grep 'wgpubkey' | cut -d ' ' -f 2`"
PUB2="`ifconfig wg2 | grep 'wgpubkey' | cut -d ' ' -f 2`"