From 240bb600f30ea37f1090e473541a676a19927ad1 Mon Sep 17 00:00:00 2001 From: Andrew Mulbrook Date: Thu, 19 Aug 2021 13:27:33 -0500 Subject: [PATCH] Add ssh-agent setup for pass-phrase protection Gonna be using pass phrase ssh keys... --- profile | 7 ++++++- scripts/ssh_session | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 scripts/ssh_session diff --git a/profile b/profile index 1b0e61f..d155ff7 100644 --- a/profile +++ b/profile @@ -12,7 +12,7 @@ if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then - . "$HOME/.bashrc" + . "$HOME/.bashrc" fi fi @@ -31,3 +31,8 @@ if [ -d "$HOME/.scripts" ] ; then PATH="$HOME/.scripts:$PATH" fi +# Enable Ssh-Agent +if [ -n "$BASH_VERSION" ]; then + . "$HOME/.scripts/ssh_session" +fi + diff --git a/scripts/ssh_session b/scripts/ssh_session new file mode 100755 index 0000000..c43e268 --- /dev/null +++ b/scripts/ssh_session @@ -0,0 +1,28 @@ +#!/bin/bash + +# +# setup ssh-agent +# + +SSH_ENV="$HOME/.ssh/environment" + +function start_agent { + echo "Initialising new SSH agent..." + /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" + echo succeeded + chmod 600 "${SSH_ENV}" + . "${SSH_ENV}" > /dev/null + /usr/bin/ssh-add; +} + +# Source SSH settings, if applicable + +if [ -f "${SSH_ENV}" ]; then + . "${SSH_ENV}" > /dev/null + ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { + start_agent; + } +else + start_agent; +fi +