Ensure you know the location of your public and private keys. In
Linux this is usually the folder ~/.ssh
, so on Windows you
may want to choose the same folder.
By default, the package looks for your private key at
~/.ssh/id_rsa
~/.ssh/id_rsa.pem
.You can change this default by setting an environment variable
USER_KEY
:
# This is optional - only do this if you want to change the default location
Sys.setenv(USER_KEY = "path/to/private/key")
Test that the package can read your key. This might fail if you don’t
have a key at ~/.ssh/id_rsa
, or if your private key has a
pass phrase and R in running in non-interactive mode.
You can create a vault by using create_vault()
A vault consists of two folders for:
users
: contains user and their public keyssecrets
: contains the encrypted secrets## [1] "README" "secrets" "users"
Alternatively, you can create a vault in an R package:
To add a user to the vault, you have to know their public key.
The secret
package contains some public and private keys
you can use for demonstration purposes.
key_dir <- file.path(system.file(package = "secret"), "user_keys")
alice_public_key <- file.path(key_dir, "alice.pub")
alice_private_key <- file.path(key_dir, "alice.pem")
openssl::read_pubkey(alice_public_key)
## [2048-bit rsa public key]
## md5: 1d858d316afb8b7d0efd69ec85dc7174
## sha256: dd0c23ae6a094e06d429ec2f471ecd661d2708bcfd71c69cd0671d8877662bcd
Add the public key of Alice to the vault:
A secret can be any R object - this object will be serialised and then encrypted to the vault.
You can decrypt a secret if you have the private key that corresponds to the public key that was used to encrypt the secret,
## password
## "my_password"
If you use windows, you most likely created your keys using
PuttyGen. Note that the key created by default from PuttyGen is not in
OpenSSH format, so you have to convert your format first. To do this,
use the /Conversions/Export OpenSSH key
menu item in
PuttyGen.
Note that the folder ~/.ssh
in Windows usually
expands to C:\\Users\\YOURNAME\\Documents\\.ssh
. You can
find the full path by using:
## [1] "/github/home/.ssh"