A lightweight bash utility that simplifies adding SSH keys to the ssh-agent with clear feedback and error handling.
- Automatic ssh-agent startup if not already running
- Flexible key specification via argument or SSH_KEY_PATH environment variable
- Cross-platform - works on Linux, macOS, and Windows (Git Bash/Cygwin)
- Safety checks - validates file existence and read permissions
- Clear output showing current identities after adding
- Built-in help with -h or --help
Download the script:
curl -o ~/bin/ssh-add-key https://raw.githubusercontent.com/your-username/ssh-key-adder/main/ssh-add-keyMake it executable:
chmod +x ~/bin/ssh-add-keyAdd to PATH (add to .bashrc/.zshrc for persistence):
export PATH="$HOME/bin:$PATH"Alternatively, clone the repository:
git clone https://github.com/your-username/ssh-key-adder.git
cp ssh-key-adder/ssh-add-key /usr/local/bin/
chmod +x /usr/local/bin/ssh-add-keyBasic usage:
ssh-add-key ~/.ssh/id_rsaAdd key with Windows path (Git Bash):
ssh-add-key /c/Users/username/.ssh/my_github_keyUse environment variable:
export SSH_KEY_PATH=~/.ssh/id_ed25519
ssh-add-keyShow help:
ssh-add-key -h
# or
ssh-add-key --helpAdd your default RSA key:
ssh-add-key ~/.ssh/id_rsaAdd an Ed25519 key for GitHub:
ssh-add-key ~/.ssh/id_ed25519Add a custom key from Windows path:
ssh-add-key "C:\Users\username\.ssh\custom_key"Error: key file not found
# Verify the path is correct
ls -la ~/.ssh/Error: failed to add key
- Ensure the key format is correct (RSA, Ed25519, etc.)
- Check if the key is password-protected and enter the correct passphrase
- Verify the key isn't already added:
ssh-add -lssh-agent not found
- Install OpenSSH client:
- Ubuntu/Debian:
sudo apt install openssh-client - macOS: Already installed
- Windows: Install Git Bash or Cygwin
- Ubuntu/Debian:
After adding your key, test it with GitHub:
ssh -T git@github.comYou should see:
Hi username! You've successfully authenticated...
Contributions are welcome! Feel free to:
- Report bugs via Issues
- Submit feature requests
- Open pull requests
This project is licensed under the MIT License - see the LICENSE file for details.
Yanin Vyacheslav
If this script helped you, consider giving it a star on GitHub! ⭐