Skip to main content

Checks whether an identity file has already been stored by the SSH agent. If not, it adds this identity by prompting for its passphrase.

Project description

ssh-agent-add-id

Checks whether an identity file has already been stored by the SSH agent. If not, it adds this identity by prompting for its passphrase.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssh_agent_add_id-0.0.7.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

ssh_agent_add_id-0.0.7-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file ssh_agent_add_id-0.0.7.tar.gz.

File metadata

  • Download URL: ssh_agent_add_id-0.0.7.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.11.2 CPython/3.10.12

File hashes

Hashes for ssh_agent_add_id-0.0.7.tar.gz
Algorithm Hash digest
SHA256 addb6e0eef2bc2839f8fe90855896e4f812a12143ec79549811a575dc70458a0
MD5 d620f7a7ef586bb0efa48bc08e21b623
BLAKE2b-256 ae135b2e2970c4fa3911be790f5886037924a07347c8c2bdaa5e6cb3257177c3

See more details on using hashes here.

File details

Details for the file ssh_agent_add_id-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for ssh_agent_add_id-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3fbb96022f69a204d79301b5ddbddb20efe6df14f0c46423d5f861c48a261c55
MD5 ca6e904a755ba331213b6d397ed4ce1c
BLAKE2b-256 6292080d69ee2e6bda71cc69a457455a7e0c7056d6ffab293aa1a8d6a1e09a97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page