Skip to content

Instantly share code, notes, and snippets.

@alexolinux
Created April 6, 2024 13:40
Show Gist options
  • Save alexolinux/bd4f580821302ed7e2ae514dcbcfcd41 to your computer and use it in GitHub Desktop.
Save alexolinux/bd4f580821302ed7e2ae514dcbcfcd41 to your computer and use it in GitHub Desktop.
Shell Script for activating SSH Agents in ZSH Environment
#!/bin/zsh
SSH_HOME="${HOME}/.ssh"
keys=($SSH_HOME/*.pem)
# Check if SSH_AUTH_SOCK is not set or is not a socket file
if [ -z "$SSH_AUTH_SOCK" ] || [ ! -S "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)"
# Add SSH keys to agent
for key in "${keys[@]}"; do
ssh-add $key > /dev/null 2>&1
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment