The default user key can be set in the USER_KEY variable and otherwise
is ~/.ssh/id_rsa. Note that on Windows we treat ~ as the windows user
home (and not the documents folder).
Details
The my_pubkey() function looks for the public key by appending .pub
to the above key path. If this file does not exist, it reads the private key file
and automatically derives the corresponding pubkey. In the latter case the user
may be prompted for a passphrase if the private key is protected.
Examples
# Set random RSA key as default
key <- rsa_keygen()
write_pem(key, tmp <- tempfile(), password = "")
rm(key)
Sys.setenv("USER_KEY" = tmp)
# Check the new keys
print(my_key())
#> [2048-bit rsa private key]
#> md5: 218de541a7843714d230d8a0c69f66e9
#> sha256: 6e49c719a96953a4b0d9abb09776a9f44013d53f5c4015f3fa5cbf6e79df1c21
print(my_pubkey())
#> [2048-bit rsa public key]
#> md5: 218de541a7843714d230d8a0c69f66e9
#> sha256: 6e49c719a96953a4b0d9abb09776a9f44013d53f5c4015f3fa5cbf6e79df1c21