Created
April 6, 2024 13:40
-
-
Save alexolinux/bd4f580821302ed7e2ae514dcbcfcd41 to your computer and use it in GitHub Desktop.
Shell Script for activating SSH Agents in ZSH Environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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