You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 1, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+44-12Lines changed: 44 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,49 +4,81 @@ Utilities for storing and loading SSH keys with 1Password. Use a unique key for
4
4
5
5
## Installation
6
6
7
-
Clone the repo and add the `bin` folder to your `PATH`. For example, with bash:
7
+
### Dependencies
8
+
9
+
-[1Password CLI][1password-cli]
10
+
-[jq][jq]
11
+
12
+
These executables (`op` and `jq`) must be available on `PATH`.
13
+
14
+
You should run `op signin` at least once before using these scripts in order to cache your basic account information. See `op signin --help` for more information.
The fetch utility stores your keys in a dedicated directory, ideally one that will not be written to disk. It also creates an SSH config file that maps the host and username specified for each key to the fetched key file. In order to use theses keys for authentication, you must include the generated config file in your own local config via an `Include` directive. For example:
30
+
31
+
Include /dev/shm/op-ssh-utils/ssh_config
32
+
33
+
Note that the path to this file may be different on systems where `/dev/shm` is not available; see [the "Environment" section](#environment) for more information.
16
34
17
35
### Automatically fetch keys before using SSH
18
36
19
-
In bash/zsh, you can define an alias for the `ssh` command which ensures your keys are fetched before connecting to a server, like so:
37
+
In many shells, you can define an alias for the `ssh` command which ensures your keys are fetched before connecting to a server, like so:
20
38
21
-
alias ssh="op-ssh-fetch -n [arguments to 'op signin']; ssh"
39
+
alias ssh="op-ssh-fetch -n; ssh"
22
40
23
41
## Usage
24
42
25
-
Note that interactive execution is not supported for any of these scripts, since `op signin` is required for all scripts and itself requires interactive password input.
26
-
27
-
By default, the key storage location is `$TMPDIR/op-ssh-utils`, where `TMPDIR` defaults to `/dev/shm` or `/tmp`, whichever is available. The key storage location can be overridden for all commands with the `OP_SSH_STORAGEDIR` environment variable.
43
+
Note that non-interactive execution is not supported for any of these scripts, since `op signin` is required for all scripts and itself requires interactive password input.
28
44
29
45
### Create a new SSH item in the vault
30
46
31
47
$ op-ssh-create -H <hostname>
32
48
33
-
Create a new vault item associated with the given host and the current username, generating a new SSH key specifically for that user on that host. It then optionally registers the new key for immediate local use.
49
+
Create a new vault item associated with the given host and the current username, generating a new SSH key specifically for that user on that host, and optionally register the new key for local use.
34
50
35
-
- Use `-u user` to log into the host as `user` rather than your current username. `-H hostname` should NOT be given in `user@host` format right now because I don't know quite enough sed magic to parse things like that.
51
+
- Use `-u user` to log into the host as `user` rather than your current username. **TODO:**`-H hostname` should NOT be given in `user@host` format right now because I don't know quite enough sed magic to parse things like that.
36
52
- Use `-i ~/.ssh/id_rsa` to use an existing keypair, `~/.ssh/id_rsa` and `~/.ssh/id_rsa.pub`, instead of generating a new keypair.
37
53
38
54
### Pull all SSH items in the vault for use locally
39
55
40
56
$ op-ssh-fetch
41
57
42
-
Search for SSH key items in your vault and read them all into temporary storage. Public and private keys will be saved to `/tmp/op-ssh-utils/keys` with appropriate permissions, and an SSH config file will be saved to `/tmp/op-ssh-utils/ssh_config` which can be included from your personal SSH config (usually `~/.ssh/config`) via `Include /tmp/op-ssh-utils`.
58
+
Search for SSH key items in your vault and register them for local use.
43
59
44
-
- Use `-n` to do nothing if keys already exist. This is useful for shell aliases.
60
+
- Use `-n` to do nothing if keys already exist. This is useful for shell aliases to only display the password prompt once per login.
45
61
46
62
### Remove all local SSH credentials
47
63
48
64
$ op-ssh-remove
49
65
66
+
Completely deletes the storage directory, undoing `op-ssh-fetch`.
67
+
68
+
## Environment
69
+
70
+
The location where keys and the temporary SSH config file are stored is given by the `OP_SSH_STORAGEDIR` environment variable, defaulting to `$TMPDIR/op-ssh-utils`. The `TMPDIR` environment variable defaults to `/dev/shm` or `/tmp`, whichever is available. `/dev/shm` is preferred since it is guaranteed to hold keys in memory, whereas `/tmp` may write to disk on some systems. Particularly if `/dev/shm` is not available, you may wish to mount your own `tmpfs` filesystem somewhere else and point `TMPDIR` to that location instead.
71
+
72
+
Within this location, the SSH config file is stored in `ssh_config`, and key pairs are stored in the `keys` subdirectory according to the UUID of their associated 1Password item.
73
+
74
+
## Using a different 1Password account
75
+
76
+
Normally, running `op signin` at least once before using these scripts caches some of your 1Password account details in your home directory. This cached account is what this script will attempt to log in as by default. If you would like to use a different account for this script than the cached one, you can pass additional arguments to `op-ssh-fetch` and `op-ssh-create` which will be passed through directly to `op signin`. For example:
See `op signin --help` for details about what arguments are expected.
81
+
50
82
# Todos
51
83
52
84
- Use a different temporary location to allow multiple users on the same system to use the tool (random folder names in the folder symlinked to `~/.local` or something? maybe just make it a bashrc script that automates adding the `Include` rule to the user's SSH config without requiring a persistent directory name across logins?)
0 commit comments