From 5c916d69d457101326803eb076a746060e3618cf Mon Sep 17 00:00:00 2001 From: Vikas Kushwaha Date: Thu, 21 Nov 2024 13:30:52 +0530 Subject: Moved from github --- .local/bin/sshadd | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 .local/bin/sshadd (limited to '.local/bin/sshadd') diff --git a/.local/bin/sshadd b/.local/bin/sshadd new file mode 100755 index 0000000..6fb3b18 --- /dev/null +++ b/.local/bin/sshadd @@ -0,0 +1,17 @@ +#!/bin/sh + +[ -z "$SSH_AUTH_SOCK" ] && export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock" +msg=$(ssh-add -L 2>&1) +if [ "$msg" = 'Could not open a connection to authentication agent.' ] || + [ "$msg" = 'Error connecting to agent: No such file or directory' ] || + [ "$msg" = 'Error connecting to agent: Connection refused' ]; then + rm -f "${SSH_AUTH_SOCK}" + ssh-agent -a "${SSH_AUTH_SOCK}" > /dev/null +fi + +private_key="$1" +content="$(cat "$1.pub")" +if [ "$msg" = "The agent has no identities." ] || + [ "${msg#*$content}" = "$msg" ]; then + ssh-add "$private_key" +fi -- cgit v1.2.3