Difference between revisions of "Ssh agent bashrc amendment"

From Wiki at Neela Nurseries
Jump to: navigation, search
m
m
Line 97: Line 97:
  
  
 +
example of newer file, effectively same variables
 +
 +
  1 379
 +
  2 /tmp/ssh-joJMd1yeEDuk/agent.378
  
 
<!-- comment -->
 
<!-- comment -->

Revision as of 22:35, 28 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 )



Example text file holding ssh-agent related variables, for export in subsequent shell instances:

 1 export SSH_AGENT_PID=4372
 2 export SSH_AUTH_SOCK=/tmp/ssh-SeAsAEx0sm7B/agent.4371


example of newer file, effectively same variables

 1 379
 2 /tmp/ssh-joJMd1yeEDuk/agent.378