Project

ssh-locate

0.0
Low commit activity in last 3 years
No release in over a year
A CLI tool and its associated Ruby library that help you locate and reconnect to a running SSH agent. Useful in automation scenarios where multiple processes must repeatedly open SSH connections leveraging a one-time authentication pass
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

ssh-locate

Build Status Gem

A command line tool that helps you locate and contact a SSH agent launched in a separate shell.

Wait, what ⁉️

This tool fills a gap in the OpenSSH suite of tools.

  • No way of knowing the PID of a running SSH Agent
  • No way of knowing the authentication socket of a running SSH Agent
  • ssh-agent only supports Bourne and C shells

Features

  • output is fully compatible with openSSH:
    SSH_AUTH_SOCK=/tmp/ssh-locate-test.15970; export SSH_AUTH_SOCK;
    SSH_AGENT_PID=12427; export SSH_AGENT_PID;
    echo Agent pid 12427;
  • supports the Fish shell
set -x SSH_AUTH_SOCK ssh-agent -a /tmp/zed
set -x SSH_AGENT_PID 1517651

(See also Fish Startup below)

  • shows EMACS Lisp to activate agent:
(setenv "SSH_AUTH_SOCK" "/tmp/zed")
(setenv "SSH_AGENT_PID" "3216002")

Installation

gem install ssh-locate

Usage

Launch your SSH agent and tell it to use a specific socket file with the -a option:

ssh-agent -a /tmp/deployer-38us9f

In a later shell (or any process running for the user who owns the agent):

Bash

$ eval `ssh-locate`
Agent pid 13457

Fish

> ssh-locate | source

EMACS

Using the --emacs option will output the lisp code to set the necessary environment variables in EMACS. Just paste this anywhere (in a scratch buffer for example) and execute eval-last-sexp (usually bound to C-x C-e) with the cursor positionned at the end of each line.

ssh-locate --emacs

Fish startup

You can launch and activate an agent at startup by adding this to your config.fish:

ssh-agent -a /tmp/arnaud
ssh-locate | source

Caveat

ssh-locate only reports the first agent found in the process table. If you have a scenario where you would like to be more specific, let me known and I can extend the selectivity. I just do not need that right now.

TODO

As the YAGNI wisdom tells us not to fantasize requirements, here are some potentially useful things that are not implemented yet:

  • Be aware of the agent launched by Ubuntu
  • Have a more sensible output if no agent was found