Hi Michael,

On Wed, Dec 16, 2020 at 01:28:15PM -0500, Michael Grant <mgr...@grant.org> 
wrote:
[...]
> Thomas, what you suggest, it's similar to the people who
> suggest symlinking some known place to the /tmp folder and then
> setting that in the environment.  Here's a link to the
> superuser.com post about this:
> 
> https://superuser.com/questions/180148/how-do-you-get-screen-to-automatically-connect-to-the-current-ssh-agent-when-re
> 
> You're right, it works a most of the time.  Where it fails is if I log
> in a second time from a different computer.  I was just looking to see
> if I could fix that.

In that case, this solution can be expanded a bit to do what you
want. The basic idea would be:
1. On login, create a directory $HOME/.ssh/sockets/$TIME/ and put
   a file setting the variables correctly in there (for example,
   name the file $HOME/.ssh/sockets/$TIME/sshenv). In that case,
   $TIME is what you get from "date +%s" (so don't login to the
   same machine from two different sources in the same second to
   avoid any trouble). At the same time, set a variable
   "remove_on_logout" to "$HOME/.ssh/sockets/$TIME/"
2. In your .logout, put this command:
   rm -fr "$remove_on_logout"
3. In your shell, set prompt_command or pre_cmd or similar to
   contain something like
   . $(ls -1 $HOME/.ssh/sockets/*/sshenv | tail -1)

This way, you will always have a working $SSH_AUTH_SOCK even
though you login and logout time and again.

> Michael

Ciao,
Thomas

-- 
 Thomas Köhler       Email:       jean-...@picard.franken.de
     <><             WWW:              http://gott-gehabt.de
                     IRC: tkoehler       Freenode: thkoehler
                     PGP public key available from Homepage!

Reply via email to