This is a sourceable shell include file which provides a sshag
function to
conveniently hook up with an operating ssh-agent
.
It will start a new agent session if it doesn't find an agent to connect with.
You might want to source it from within your ~/.bashrc
file or other profile
script.
It can also be run as an executable script, and its output stored in the relevant environment variable. This is particularly useful when it is desired to configure a non-shell environment, for example, that of a text editor.
Messages are emitted on standard out; the output will always consist of just the socket location.
Use the pearl package manager.
# install
pearl_conf="${XDG_CONFIG_HOME:-$HOME/.config}/pearl/pearl.conf"
if grep '^}$' >/dev/null 2>&1 "$pearl_conf"; then
sed -i.bak 's/^}$//' "$pearl_conf"
else
printf '%s\n' 'PEARL_PACKAGES = {' > "$pearl_conf"
fi
printf '"%s": {\n' 'sshag' >>"$pearl_conf"
printf '"%s": "%s"\n' \
'url' 'https://github.com/go2null/sshag.git' \
>>"$pearl_conf"
printf '"%s": "%s"\n' \
'description' 'Hook up with an operating or new SSH agent' \
>>"$pearl_conf"
printf '{\n' >>"$pearl_conf"
pearl install sshag
# update
pearl update sshag
# install
wget https://raw.githubusercontent.com/go2null/sshag/stable/sshag.sh
sh sshag.sh install
# update
sshag update
# uninstall/remove
sshag remove
Sourced
$ ssh alotta@fagina.example.com
Enter passphrase for key '/home/austin/.ssh/id_ed25519': ^C
$ sshag alotta@fagina.example.com
Keys:
256 SHA256:2TWr3x/H6eGvE+vx9Ur8uFQWBIXTBH3jT12yHBB4TJY austin@powers (ED25519)
Invoked
$ export SSH_AGENT_SOCK=$(sh ~/.local/share/lib/sshag/sshag.sh)
Output should be assigned to the environment variable SSH_AUTH_SOCK.
Keys:
256 SHA256:2TWr3x/H6eGvE+vx9Ur8uFQWBIXTBH3jT12yHBB4TJY austin@powers (ED25519)
See CHANGELOG.md.
This code was posted as a response to a question on superuser.com. As I understand it, code posted to that site is under the terms of the Creative Commons Attribution-Sharealike License, so I'm attributing it to the superuser.com user Zed. SU currently links to version 2.5 of the license.
A copy of the full license is distributed herein in the file LICENSE.
- to Share — to copy, distribute and transmit the work
- to Remix — to adapt the work
- Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
- Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
-
Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
-
Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
-
Other Rights — In no way are any of the following rights affected by the license:
-
Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.