Skip to main content

ssh_from_env

What would you do if a device on which you've stored your private ssh key files, is lost, stolen or damaged?

This small script allows a (basic, slow) ssh log-in shell session to be created using Fabric and Paramiko, from a private ssh key stored in an environment variable. Services such as Hashicorp Vault can run scripts such as this one, passing them secrets as environment variables. This makes saving copies of private key files (whether temporary or permanent) on a local disk unnecessary.

I do not claim this is best practise. Nor that it scales (vault services can be used to authenticate ssh certificates instead).
This script is only intended to be a simple mitigation to loss, theft and damage of physical devices.

Users able to rely on managed physical copies of ssh key files, do not need this library at all. For the rest of us, please note this not a hardened magic bullet to manage all your security issues. Produce your own security model. In particular this approach: a) delegates important security decisions to second and third parties, in no particular order: myself, my own infrastructure and dependency providers, and your chosen cloud vault service provider(s). This script is a trade off. It is intended to make you less vulnerable to all your offices burning down or devices being stolen. But as with moving anything from on-prem to the cloud, this is always at the cost of exposing you to others' vulnerabilities instead. b) the vault service(s) themselves must now be secured. By their very nature, credible providers have considered this at length, e.g. requiring password, and either a OTP or a recovery code (storing recovery codes on the devices instead of ssh key files, just shifts the problem to a different file, and adds only a little obscurity, not any extra security).

Usage:

  1. Create an account with a Vault provider with a CLI, e.g. Hashicorp Vault. Install this provider's CLI. Copy the contents of the RSA private key file into a secret in this service (ssh_from_env will look for a secret called SSH_KEY by default).
  2. pipx install ssh_from_env
  3. Run the main entrypoint script, via the Vault provider's CLI, that grants access to the secrets as environment variables.
hcp vault-secrets run -- ssh_from_env user@host (env_var_name=SSH_KEY)

Alternatives

Hard disk encryption or encrypted containers/volumes/partitions (e.g. Veracrypt)

Pros

  • Tested, established tools.
  • Simple to backup.

Cons

  • Not a mitigation by themselves alone for loss or damage (backups also required for this).
  • Extra passphrase to remember/store, or passphrase reuse required.
  • No audit trail
  • Credentials need to be entered each session to mount, as they are not remembered (it could also be argued this is a "Con" of a Vault service).

Metadata

Release files for ssh-from-env 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ssh-from-env 0.0.0
File Size Uploaded Provenance Actions
ssh_from_env-0.0.0.tar.gz 3.9 kB Without provenance Details for ssh_from_env-0.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ssh-from-env 0.0.0
File Interpreter ABI Platform Actions
ssh_from_env-0.0.0-py3-none-any.whl Python 3 none any Details for ssh_from_env-0.0.0-py3-none-any.whl

Total release size: 9.0 kB

Release files / ssh_from_env-0.0.0.tar.gz

Download URL ssh_from_env-0.0.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
808da5c711a79cdd9b8db9cf553e541e3649e3ac931f12e03da0844d5c6b77cc
BLAKE2b-256 checksum
How to use checksums
d08dbfde8f7c39f1093c9732d5e30e395977d356e459e9a672675402038ecec1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.4

Release files / ssh_from_env-0.0.0-py3-none-any.whl

Download URL ssh_from_env-0.0.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f39208ee718593a8868bdde4b77ed972ea1c539d5f707c9a3f48b72dad09321c
BLAKE2b-256 checksum
How to use checksums
76773167273e6953fd4669d9731b40b0c1b2dc2ede7e5d0a402c2030b850748d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.4

Security for ssh-from-env 0.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page