Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to set static path for SSH_AUTH_SOCK #118

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions keychain.pod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ keychain - re-use ssh-agent and/or gpg-agent between logins

S<keychain [ -hklQqV ] [ --clear --confhost --confallhosts --gpg2 --help --ignore-missing --list>
S<--noask --nocolor --nogui --nolock --quick --quiet --version ]>
S<[ --agents I<list> ] [ --attempts I<num> ] [ --dir I<dirname> ]>
S<[ --host I<name> ] [ --lockwait I<seconds> ]>
S<[ --agents I<list> ] [ --agent-socket I<list> ] [ --attempts I<num> ]>
S<[ --dir I<dirname> ] [ --host I<name> ] [ --lockwait I<seconds> ]>
S<[ --stop I<which> ] [ --timeout I<minutes> ] [ keys... ]>

=head1 DESCRIPTION
Expand Down Expand Up @@ -63,6 +63,11 @@ Start the agents listed. By default keychain will start ssh-agent
if it is found in your path. The list should be comma-separated,
for example "gpg,ssh"

=item B<--agent-socket> I<path>

Path for SSH_AUTH_SOCK. If set, ssh-agent will try to bind the socket to
the given path.

=item B<--attempts> I<num>

Try num times to add keys before giving up. The default is 1.
Expand Down
12 changes: 11 additions & 1 deletion keychain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ color=true
inheritwhich=local-once
unset stopwhich
unset timeout
unset agent_socket
unset ssh_timeout
attempts=1
unset sshavail
Expand Down Expand Up @@ -609,7 +610,7 @@ startagent() {
# Branch again since the agents start differently
mesg "Starting ${start_prog}-agent..."
if [ "$start_prog" = ssh ]; then
start_out=$(ssh-agent ${ssh_timeout})
start_out=$(ssh-agent ${ssh_timeout} ${ssh_agent_socket})
elif [ "$start_prog" = gpg ]; then
if [ -n "${timeout}" ]; then
gpg_cache_ttl="$(expr $timeout \* 60)"
Expand Down Expand Up @@ -1152,6 +1153,10 @@ while [ -n "$1" ]; do
--nocolor)
color=false
;;
--agent-socket)
shift
agent_socket=$1
;;
--timeout)
shift
if [ "$1" -gt 0 ] 2>/dev/null; then
Expand Down Expand Up @@ -1312,6 +1317,11 @@ fi
# If there are no agents remaining, then bow out now...
[ -n "$agentsopt" ] || { qprint; exit 0; }

# --agent-socket translates argument into `-a` argument to set static SSH_AUTH_SOCKET
if [ -n "$timeout" ] && wantagent ssh; then
ssh_agent_socket="-a $agent_socket"
fi

# --timeout translates almost directly to ssh-add/ssh-agent -t, but ssh.com uses
# minutes and OpenSSH uses seconds
if [ -n "$timeout" ] && wantagent ssh; then
Expand Down