public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Andrey Repin <anrdaemon@yandex.ru>
To: Chris Rodgers <ctr28@cam.ac.uk>, cygwin@cygwin.com
Subject: Re: ssh-pageant
Date: Thu, 23 Apr 2020 23:02:02 +0300	[thread overview]
Message-ID: <373832437.20200423230202@yandex.ru> (raw)
In-Reply-To: <5f24168f-61d7-848b-677d-bf0d5aea303a@cam.ac.uk>

Greetings, Chris Rodgers!

> I find the ssh-pageant package helpful to enable cygwin ssh to interact
> seamlessly with PuTTY's Pageant SSH agent. One small issue is that after 
> installing, one has to add the lines:

>> |# ssh-pageant eval $(/usr/bin/ssh-pageant -r -a 
>> "/tmp/.ssh-pageant-$USERNAME")|
> (see https://github.com/cuviper/ssh-pageant) 
> <https://github.com/cuviper/ssh-pageant>to .bashrc for each user.

> Would it be acceptable to update the ssh-pageant package to add a file 
> /etc/profile.d/ssh-pageant.sh that does this automatically?

It's not that simple. You can't blindly restart agent every time you wish
without notifying other programs, `--reuse` is a very bad idea and there's
no easy way to set/change an environment variable globally for an entire
user session.

> Or is there another preferred way to do this, e.g. a postinstall script?

> I'd be happy to draft a script file for review.

Just create a script for yourself and amend your own .bashrc accordingly.

I do it this way:

1. Add

----- 8< ----- 8< ----- 8< ----- 8< -----
# Import ssh-pageant settings
test -f "$HOME/.ssh/agent" && . "$HOME/.ssh/agent"
----- >8 ----- >8 ----- >8 ----- >8 -----

near the end of .bashrc

2. Create a script `$HOME/profile.d/ssh-pageant.sh`

----- 8< ----- 8< ----- 8< ----- 8< -----
#!/bin/sh

[ -x /usr/bin/ssh-pageant ] || return

_agent="$HOME/.ssh/agent"
eval set -- $( getopt --shell=sh -o 'k' -- "$@" )

test -f "$_agent" && . "$_agent"

if [ "$SSH_PAGEANT_PID" ]; then
  if test "$1" = "-k"; then
    /usr/bin/ssh-pageant -qk 2> /dev/null
  fi

  if ! kill -0 "$SSH_PAGEANT_PID" 2> /dev/null; then
    # Reap dead agent's socket
    rm "$SSH_AUTH_SOCK" "$_agent" 2> /dev/null
    unset SSH_AUTH_SOCK SSH_PAGEANT_PID
  fi
fi

test "$1" = "-k" && exit
test "$SSH_PAGEANT_PID" && exit

socket="$( mktemp -u /var/run/ssh-XXXXXXXX )"
eval $( cygdrop -- /usr/bin/ssh-pageant -qsa "$socket" | tee "$_agent" )

# Remove empty settings file (agent failed to start).
test -s "$_agent" || rm "$_agent"
----- >8 ----- >8 ----- >8 ----- >8 -----

3. Create login job to run scripts from ~/profile.d/ on user login.

4. If you need agent settings in a different script, that may be run outside
normal terminal/shell workflow, just add

----- 8< ----- 8< ----- 8< ----- 8< -----
test -f "$HOME/.ssh/agent" && . "$HOME/.ssh/agent"
----- >8 ----- >8 ----- >8 ----- >8 -----

near the top.

5. Don't forget to `ssh-pageant.sh -k` before running Cygwin setup.


-- 
With best regards,
Andrey Repin
Thursday, April 23, 2020 21:28:24

Sorry for my terrible english...


  parent reply	other threads:[~2020-04-23 20:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 13:50 ssh-pageant Chris Rodgers
2020-04-23 14:11 ` ssh-pageant Thomas Wolff
2020-04-23 18:31   ` ssh-pageant Andrey Repin
2020-04-23 18:59     ` ssh-pageant Thomas Wolff
2020-04-23 20:27       ` ssh-pageant Bill Stewart
2020-04-23 16:40 ` ssh-pageant Chris Rodgers
2020-04-23 16:47   ` ssh-pageant Chris Rodgers
2020-04-23 19:44     ` ssh-pageant Chris Rodgers
2020-04-23 18:33 ` ssh-pageant Brian Inglis
2020-04-23 20:02 ` Andrey Repin [this message]
2020-04-23 20:20   ` ssh-pageant Chris Rodgers
2020-04-23 20:51     ` ssh-pageant Andrey Repin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=373832437.20200423230202@yandex.ru \
    --to=anrdaemon@yandex.ru \
    --cc=ctr28@cam.ac.uk \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).