how to check ssh agent is running in git bash 1

how to check ssh agent is running in git bash

# Set up ssh-agent
SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initializing new SSH agent..."
    touch $SSH_ENV
    chmod 600 "${SSH_ENV}"
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' >> "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add
}

# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    kill -0 $SSH_AGENT_PID 2>/dev/null || {
        start_agent
    }
else
    start_agent
fi

Here is what the above code is Doing:
1. It creates a file called .ssh/environment in your home directory.
2. It checks to see if there’s already an ssh-agent running. If there is, it uses that one. If not, it starts a new one.
3. It adds your SSH key to the ssh-agent.
4. It sources the .ssh/environment file so that your current shell session knows about your SSH key.

Now, you can use your SSH key to authenticate with GitHub.

Similar Posts