Skip to main content

ssh-agent-add-id

PyPI version Python versions

A wrapper for ssh-add that checks whether a key has already been added to the SSH agent rather than prompting for the passphrase every time.


Description

ssh-agent-add-id was primarily created to address a pending issue in the VS Code WSL extension when authenticating with an SSH key that requires a passphrase, such as for a remote Git repository. If this key has not been previously added to the SSH agent accessible from the WSL extension, VS Code does not prompt for the passphrase, causing operations like pushing to the remote repository to get stuck.

ssh-agent-add-id serves as a wrapper for the ssh-add command. However, unlike the latter, it does not prompt again for the passphrase and exits quietly if the key has already been added to the SSH agent. It can thus be easily executed in a VS Code task when a project is opened.

And beyond remote Git repositories and WSL, ssh-agent-add-id can be also be used with cloud services that rely on SSH key authentication and thus reduce the number of times you need to enter your passphrases.


Requirements

SSH agent

  • ssh-add and ssh-agent must be installed and running.
  • SSH_AUTH_SOCK environment variable needs be set and accessible from VS Code environment.
  • For Linux/WSL, in order to share a single ssh-agent process for all your shells, it is highly recommended to either run ssh-agent as an user-level systemd service or to install and setup Keychain.

ssh-agent-add-id

  • Requires Python 3.8+.
  • It should run smoothly on macOS and all Linux distributions. However, on Windows, it only runs within WSL.

Installation

ssh-agent-add-id can be installed using pip:

pip install ssh-agent-add-id

VS Code task

Add a task to your VS Code project (in .vscode/tasks.json). Do not forget to update the "args" value with the actual path of your private key file:

    {
      "label": "Add Git SSH key to agent",
      "type": "shell",
      "command": "ssh-agent-add-id",
      "args": ["${userHome}/.ssh/<PRIVATE_KEY_FILE>"],
      "presentation": {
        "panel": "new",
        "revealProblems": "onProblem",
        "close": true
      },
      "runOptions": {
        "runOn": "folderOpen"
      },
      "problemMatcher": []
    }

Thanks to "runOptions"/"runOn": "folderOpen", this task runs every time your project is opened, launching a new dedicated terminal. If the identity/key was already added to the SSH agent, this terminal closes immediately. Otherwise, it prompts for the key passphrase.


Command line usage

usage: ssh-agent-add-id [-h] [--version] priv_key_path [pub_key_path]

positional arguments:
  priv_key_path  the path of the private key file
  pub_key_path   the path of the public key file in case its filename is not <priv_key_path>.pub

optional arguments:
  -h, --help     show this help message and exit
  --verbose      print some extra info
  --version      show program's version number and exit

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for ssh-agent-add-id 0.0.9

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-agent-add-id 0.0.9
File Size Uploaded
ssh_agent_add_id-0.0.9.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ssh-agent-add-id 0.0.9
File Interpreter ABI Platform
ssh_agent_add_id-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / ssh_agent_add_id-0.0.9.tar.gz

Download URL ssh_agent_add_id-0.0.9.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2263762e29df440378651fa7e7836b94dc0585a7cb02459882d41acb50fc4bbd
BLAKE2b-256 checksum
How to use checksums
ddfc4bb0b5a93960a128ae9083fd992884897b659f208d8b5134b0c596cd708b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.15.4 CPython/3.10.12 Linux/6.5.0-1021-azure

Release files / ssh_agent_add_id-0.0.9-py3-none-any.whl

Download URL ssh_agent_add_id-0.0.9-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06fcf19134820d9c823cb8c8365e13b3d68a637904cc2e77989ea081236f6288
BLAKE2b-256 checksum
How to use checksums
c2e6d017e33ff3fb55a0c8ab3aa9297e69d3cd2c9e34af239c36bd9bb9576298
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.15.4 CPython/3.10.12 Linux/6.5.0-1021-azure

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

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