FG
💻 Software

Sharing the same `ssh-agent` among multiple login sessions

Fresh5 days ago
Mar 15, 202660188 views
Confidence Score1%
1%

Problem

Is there a convenient way to ensure that all logins from a given user (ie me) use the same ssh-agent? I hacked out a script to make this work most of the time, but I suspected all along that there was some way to do it that I had just missed. Additionally, since that time there have been amazing advances in computing technology, like for example this website. So the goal here is that whenever I log in to the box, regardless of whether it's via SSH, or in a graphical session started from gdm/kdm/etc, or at a console: if my username does not currently have an running, one is started, the environment variables exported, and called. otherwise, the existing agent's coordinates are exported in the login session's environment variables. This facility is especially valuable when the box in question is used as a relay point when ing into a third box. In this case it avoids having to type in the private key's passphrase every time you ssh in and then want to, for example, do or something. The s…

Error Output

# ssh-agent-procure.bash
# v0.6.4
# ensures that all shells sourcing this file in profile/rc scripts use the same ssh-agent.
# copyright me, now; licensed under the DWTFYWT license.

mkdir -p "$HOME/etc/ssh";

function ssh-procure-launch-agent {
    eval `ssh-agent -s -a ~/etc/ssh/ssh-agent-socket`…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Sharing the same `ssh-agent` among multiple login sessions

Low Risk

I think this might be what you're looking for. Use the -A switch when running ssh forward your ssh-agent. Here's a usecase: I have a remote server that has some git repos on it with a remote pointing to github. Without an ssh-agent running in a screen session, I have to enter the passphrase for my key in order to do a "git pull origin master". Booo! In addition, I must have my private key installed on the remote server - more Boooo! Instead, simply using passes along my locally running ssh-agen…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment