Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit 287f4cf

Browse files
authored
Revise documentation in README
1 parent ceb18e6 commit 287f4cf

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,81 @@ Utilities for storing and loading SSH keys with 1Password. Use a unique key for
44

55
## Installation
66

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.
15+
16+
[1password-cli]: https://support.1password.com/command-line-getting-started/
17+
[jq]: https://stedolan.github.io/jq/
18+
19+
### Adding the scripts
20+
21+
Clone the repo anywhere on your computer and add the `bin` folder to your `PATH`. For example, with bash:
822

923
cd ~/.local
1024
git clone https://github.com/eritbh/1password-ssh-utils.git
1125
echo 'export PATH="~/.local/1password-ssh-utils/bin:$PATH"' >> ~/.bashrc
1226

13-
Ensure that you also have the [1Password CLI](1password-cli) available as `op` via `PATH`.
27+
### Setting up your SSH config
1428

15-
[1password-cli]: https://support.1password.com/command-line-getting-started/
29+
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.
1634

1735
### Automatically fetch keys before using SSH
1836

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:
2038

21-
alias ssh="op-ssh-fetch -n [arguments to 'op signin']; ssh"
39+
alias ssh="op-ssh-fetch -n; ssh"
2240

2341
## Usage
2442

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.
2844

2945
### Create a new SSH item in the vault
3046

3147
$ op-ssh-create -H <hostname>
3248

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.
3450

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.
3652
- Use `-i ~/.ssh/id_rsa` to use an existing keypair, `~/.ssh/id_rsa` and `~/.ssh/id_rsa.pub`, instead of generating a new keypair.
3753

3854
### Pull all SSH items in the vault for use locally
3955

4056
$ op-ssh-fetch
4157

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.
4359

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.
4561

4662
### Remove all local SSH credentials
4763

4864
$ op-ssh-remove
4965

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:
77+
78+
op-ssh-fetch my.1password.com [email protected] YOUR-SECRET-KEY
79+
80+
See `op signin --help` for details about what arguments are expected.
81+
5082
# Todos
5183

5284
- 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

Comments
 (0)