Giter VIP home page Giter VIP logo

ssh-find-agent's Introduction

ssh-find-agent

ssh-find-agent is a tool for locating existing ssh compatible agent processes (e.g., ssh-agent, gpg-agent, gnome-keyring, osx-keychain); and, optionally, setting SSH_AUTH_SOCK accordingly.

Build Status

Build Status

Usage

Somewhere in shell initialization (~/.bashrc or ~./.zshrc)

source ssh-find-agent.sh # for bash
emulate ksh -c "source ssh-find-agent.sh" # for zsh

Add the following to automatically choose the first agent

ssh-add -l >&/dev/null || ssh-find-agent -a || eval $(ssh-agent) > /dev/null

To choose the agent manually run

ssh-find-agent -c

NOTE: The choose option is Useful when you actually want multiple agents forwarded. E.g., while pairing.

To list the agents run

ssh-find-agent -l

This will return a list of export commands that can be used to set the socket.

Should this output be executed it will set the socket to the last agent found.

eval $(ssh-find-agent -l)

Status

Alternatives

ssh-find-agent's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssh-find-agent's Issues

Kind of slow, anyway to improve it?

At first thanks for this great helper script, it's exactly a time saver for me to set the ssh-agent environment variable automatically.

However, I noticed that it will cost about 3 seconds on my VPS, is there any way to reduce this start time? Instead of a noticeable 3 seconds, 0.5-1 second would be smoother.

Failure running under zsh

If I run on zsh with the current master I get a failure:

fingerprints:3: bad pattern: #

I think this can be fixed by escaping the hash in the pattern here. That is

-        [[ -n $l && ${l###} = $l ]] && ssh-keygen -l -f /dev/stdin <<<$l
+        [[ -n $l && ${l##\#} = $l ]] && ssh-keygen -l -f /dev/stdin <<<$l

I've checked that this change still produces the correct behaviour in the test on both bash and zsh, but I haven't done anything more extensive.

OSX

Hello,

This doesnt work in Mavericks OSX. Is there something that needs to be changed..

Multiple users

Hi!
First of all, great and useful piece of work!
I'm seeing that in case you have multiple users with multiple agents running (my case) the script does not work, I guess because it tries to connect with sockets it has no permissions on.
Any quick fix?
Thanks!!

Xavi.

Speed: potentially integrate multiple find calls and (maybe) do away with grep.

ssh-find-agent is 50% of my shell startup time

Clearly a lot of time is spent at
https://github.com/wwalker/ssh-find-agent/blob/master/ssh-find-agent.sh#L76-L84

Where find is called multiple times against multiple paths.

I think we can do better:

  1. Use the -o syntax of find, https://superuser.com/questions/1494617/what-is-the-o-argument-in-find-command
  2. Potentially adjust the existing find calls to do away with the post-grep (although you can instead combine the grep into a single one)

I'm going to look into how this works, but find is black magic and difficult, so I'm stating my intention here.

on Amazon Linux 2 ssh-find-agent's output includes "garbage"

I suspect it is a bash version issue.

$ eval "$(ssh-find-agent)"
-bash: syntax error near unexpected token `RSA'
$ printf "<%s>\n" "$(ssh-find-agent)"
<export SSH_AUTH_SOCK=/tmp/ssh-uJ7Ualz2Tu/agent.28347   #1)     wwalker@polonium (RSA)
waywalke@polonium (RSA)   >
$ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-koji-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$

MacOS (at least 10.14) directories "wrong"

Hi there,

Under macOs 10.14.6, the following is places/examples of ssh-agent listening:

The "stock" macOS ssh-agent listening under launchd:

/private/tmp/com.apple.launchd.{RandomString}/Listeners

The HomeBrew OpenSSH:

/var/folders/4q/{Random-string}/T//ssh-{randomg-string}/agent.{PID}

This is compared to /tmp that points to private/tmp thus this script doesn't match any thing for macOs 10.14.6 ;(

authorized_keys

Hi

Your script uses the file ".ssh/authorized_keys", but you don't verify before if this file exists (in my case, there was no)

v1.0 branch - RHEL7 ssh-add -l bug

ssh-add -l on RHEL 7 and its derivatives, returns 141 instead of zero when talking to a modern forwarded ssh-agent because the modern agent doesn't respond to queries for Protocol 1 keys. And it writes an error to stderr.

SSH_AUTH_SOCK=rm -rf /tmp/ssh-*** on v1.0

First of all: Thanks for this nice little helper script :) I've been using it for a while and it does exactly what I need it to do (up until now).

I'm seing a bit of a weird behaviour when using the ssh-find-agent -a option when I have dead sockets. I'm experiencing this in WSL2 (Ubuntu2204 on Win11). I guess WSL2 isn't cleaning up sockets as nicely as it should for some reason.

This is what I get when there is an existing dead socket when I start WSL2:

socket (/tmp/ssh-XXXXXXCaNwA7/agent.6220) is dead, removing it.
Error connecting to agent: No such file or directory
$ env | grep SSH
SSH_AUTH_SOCK=rm -rf /tmp/ssh-XXXXXXCaNwA7
SSH_AGENT_PID=1

I've traced this to the "echo" of the rm command here:
https://github.com/wwalker/ssh-find-agent/blob/master/ssh-find-agent.sh#L92

It is assumed that the last line of the sfa_print_choose_menu output is a socket here:
https://github.com/wwalker/ssh-find-agent/blob/master/ssh-find-agent.sh#L187

Since the function echos the rm, it is assumed to be the agent.

I believe that the fix here is to change from echo to sfa_debug. Does that sound about right?

v1.0 needs -l functionality

Implement ssh-find-agent -l to list all running, communicating agents.

Older versions of ssh-find-agent would output a list of the running agents if ssh-find-agent was run with no options.

in v1.0 branch, may choose dead socket

There were 4 dead sockets and 1 live socket (which had 3 keys).

I ran ssh-find-agent -a; then, there were 4 dead sockets and 1 live socket (which had 3 keys).

However, it chose one of the sockets that it "cleaned up" rather than a live socket.

seems to display agents twice when run with -c

$ ssh-find-agent -c                                                                                                                                                                                                                                                                           
1) /tmp/ssh-XPxQQoEviV/agent.2653:0
        The agent has no identities.
2) /tmp/ssh-XPxQQoEviV/agent.2653:0
        The agent has no identities.
3) /tmp/ssh-aYzoS8aJIL/agent.32101:1
        4096 82:11:95:e6:a6:7e:18:70:fc:d8:61:ae:3c:f7:0c:10 cardno:000604171938 (RSA)
4) /tmp/ssh-aYzoS8aJIL/agent.32101:1
        4096 82:11:95:e6:a6:7e:18:70:fc:d8:61:ae:3c:f7:0c:10 cardno:000604171938 (RSA)
5) /tmp/ssh-EwQgyjve8UzL/agent.26532:1
        2048 c7:fc:d3:77:dd:d9:91:74:9b:6d:7a:83:fc:50:a4:33 .ssh/id_rsa (RSA)
6) /tmp/ssh-EwQgyjve8UzL/agent.26532:1
        2048 c7:fc:d3:77:dd:d9:91:74:9b:6d:7a:83:fc:50:a4:33 .ssh/id_rsa (RSA)

Document the need to emulate ksh or bash for zsh users

Hi! Some issues in the past where the script fails in zsh environment is because of the usage of word splitting, e.g. for i in $lines, which is disabled by default in zsh. So we might be able to document the behavior, by simply adding a line emulate ksh -c '. ssh-find-agent.sh' in the README.

The alternative to this is to check on $SHELL or $ZSH_VERSION for zsh users, and set setopt word_splitting explicitly, and that would require code changes, and proper handling of unsetting the option.

What do you think? Recommend just the docs change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.