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.
Sourced:
$ ssh [email protected]
Enter passphrase for key '/home/austin/.ssh/id_dsa': ^C
$ source sshag.sh
$ sshag
Keys:
2048 0d:db:a1:1a:cc:01:ad:ec:ab:00:d1:ed:eb:ac:1e:00 /home/austin/.ssh/id_dsa (DSA)
/tmp/ssh-5ock3tt0m3/agent.6969
$ ssh [email protected]
...
Invoked:
$ export SSH_AGENT_SOCK=`sshag.sh`
Output should be assigned to the environment variable $SSH_AUTH_SOCK.
Keys:
2048 0d:db:a1:1a:cc:01:ad:ec:ab:00:d1:ed:eb:ac:1e:00 /home/austin/.ssh/id_dsa (DSA)
Appended to ~/.bashrc
:
source ~/lib/sshag/sshag.sh; sshag &>/dev/null
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 COPYING.
- 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.