diff --git a/docs/backends/age.md b/docs/backends/age.md index 181986f973..d1e840a8da 100644 --- a/docs/backends/age.md +++ b/docs/backends/age.md @@ -37,6 +37,11 @@ $ GOPASS_AGE_PASSWORD=mypassword gopass init --crypto age Notice the extra space in front of the command to skip most shell's history. You'll need to set your name and username using `git` directly if you're using it as storage backend (the default one). +You can also specify the ssh directory by setting environment variable +``` +$ GOPASS_SSH_DIR=/Downloads/new_ssh_dir gopass init --crypto age +``` + ## Features * Encryption using `age` library, can be decrypted using the `age` CLI diff --git a/docs/config.md b/docs/config.md index 5488748071..632ecbe8b5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -34,6 +34,7 @@ Some configuration options are only available through setting environment variab | `GOPASS_NO_NOTIFY` | `bool` | Set to any non-empty value to prevent notifications | | `GOPASS_NO_REMINDER` | `bool` | Set to any non-empty value to prevent reminders | | `GOPASS_PW_DEFAULT_LENGTH` | `int` | Set to any integer value larger than zero to define a different default length in the `generate` command. By default the length is 24 characters. | +| `GOPASS_SSH_DIR` | `string` | Set to a filepath that contains ssh keys. Overrides default location. | | `GOPASS_UMASK` | `octal` | Set to any valid umask to mask bits of files created by gopass | | `GOPASS_UNCLIP_CHECKSUM` | `string` | (internal) Used between gopass and it's unclip helper. | | `GOPASS_UNCLIP_NAME` | `string` | (internal) Used between gopass and it's unclip helper. | diff --git a/internal/backend/crypto/age/ssh.go b/internal/backend/crypto/age/ssh.go index fd9d244661..56ae9dae94 100644 --- a/internal/backend/crypto/age/ssh.go +++ b/internal/backend/crypto/age/ssh.go @@ -34,9 +34,9 @@ func (a *Age) getSSHIdentities(ctx context.Context) (map[string]age.Identity, er sshDir, err := getSSHDir() if err != nil { - debug.Log("asdf: %s", err) + debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir) - return nil, fmt.Errorf("asdf: %w", err) + return nil, fmt.Errorf("no identities found: %w", err) } files, err := os.ReadDir(sshDir) @@ -68,27 +68,20 @@ func (a *Age) getSSHIdentities(ctx context.Context) (map[string]age.Identity, er func getSSHDir() (string, error) { preferredPath := os.Getenv("GOPASS_SSHDIR") - if preferredPath != "" { - return preferredPath, nil - } sshDir := filepath.Join(preferredPath, ".ssh") - if !fsutil.IsDir(sshDir) { - debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir) - - return "", fmt.Errorf("no identities found: %w", ErrNoSSHDir) + if fsutil.IsDir(sshDir) { + return preferredPath, nil } // notice that this respects the GOPASS_HOMEDIR env variable, and won't // find a .ssh folder in your home directory if you set GOPASS_HOMEDIR uhd := appdir.UserHome() sshDir = filepath.Join(uhd, ".ssh") - if !fsutil.IsDir(sshDir) { - debug.Log("no .ssh directory found at %s. Ignoring SSH identities", sshDir) - - return "", fmt.Errorf("no identities found: %w", ErrNoSSHDir) + if fsutil.IsDir(sshDir) { + return sshDir, nil } - return "", nil + return "", ErrNoSSHDir } // parseSSHIdentity parses a SSH public key file and returns the recipient and the identity.