Difference between revisions of "Ssh agent bashrc amendment"

From Wiki at Neela Nurseries
Jump to: navigation, search
m
m
Line 71: Line 71:
 
SESA143118@WTUSLVSE134642L MINGW64 ~/Desktop
 
SESA143118@WTUSLVSE134642L MINGW64 ~/Desktop
  
 +
 +
Example output on second and successive invocations:
 +
 +
starting,
 +
script called without bookmarked paths group specified,
 +
looking for last-used bookmarks group in dot-bash-amendments run-time config file . . .
 +
- DEV - from rc file read bookmarks group id '5',
 +
calling 'read directory bookmarks file' with arguments '/usr/bin/bash 5' . . .
 +
caller requests valid bookmarks file identified by '5', which is in the range 1..9
 +
will read bookmarks from file named bookmarked-paths-05.txt,
 +
Checking for ssh-agent daemon process:
 +
Found one or more ssh-agent processes running,
 +
Reading env variables relating to earliest started ssh-agent instance...
 +
exporting 1587 to SSH_AGENT_PID env var...
 +
exporting /tmp/ssh-dDf7ojhRm54x/agent.1586 to SSH_AUTH_SOCK env var...
 +
done.
  
 
-->
 
-->
  
 
<!-- comment -->
 
<!-- comment -->

Revision as of 20:56, 14 January 2021


The following bash script snippet is part of a larger "dot bash run-time config" amendments script, written and utilized by Ted Havelka over the years from about 2006 to 2021. This snippet is geared toward amending one or multiple shell instances in a Gitbash environment, in which ssh-agent is used to hold one or more SSL keys for remote git access. The snippet here assumes that the user's given ssh-agent has already had those key pairs successfully added to its local sense and stock of SSL keys.

Some good instructions for created and adding keys to ssh-agent were found by Ted on 2021-01-13 WED at https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent.


# 2020-10-30 FRI - work to configure ssh-agent per gitbash session:

LOCAL_VAR_SSH_AGENT_RUNNING_PROCESS_COUNT=$(ps -u $USERNAME | grep agent | wc | awk '{print $1}')
LOCAL_VAR_SSH_AGENT_VARS_FILENAME="z--ssh-agent-env-vars.txt"

echo "Checking for ssh-agent daemon process:"

if [ $LOCAL_VAR_SSH_AGENT_RUNNING_PROCESS_COUNT -ne 0 ]; then
    echo "Found one or more ssh-agent processes running,"
    if [ -e $LOCAL_VAR_SSH_AGENT_VARS_FILENAME ]; then
        echo "Reading env variables relating to earliest started ssh-agent instance..."
        var1=$(cat $LOCAL_VAR_SSH_AGENT_VARS_FILENAME | sed -n '1p')
        var2=$(cat $LOCAL_VAR_SSH_AGENT_VARS_FILENAME | sed -n '2p')
        echo "exporting $var1 to SSH_AGENT_PID env var..."
        export SSH_AGENT_PID=$var1
        echo "exporting $var2 to SSH_AUTH_SOCK env var..."
        export SSH_AUTH_SOCK=$var2
    else
        echo "but no locally written environment vars found!"
    fi
else
    echo "none found, starting..."
    eval $(/usr/bin/ssh-agent -s)
    /usr/bin/ssh-add $HOME/.ssh/id-ed25519-key
    var3=$(set | grep SSH_AGENT_PID | cut -d'=' -f 2)
    var4=$(set | grep SSH_AUTH_SOCK | cut -d'=' -f 2)
    echo "var3 holds $var3"
    echo "var4 holds $var4"
    echo "Writing these variables to file for future Gitbash shell instances to read..."
    echo $var3 > $LOCAL_VAR_SSH_AGENT_VARS_FILENAME
    echo $var4 >> $LOCAL_VAR_SSH_AGENT_VARS_FILENAME
fi


echo "done."



# EOF ( end of file )