Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SSH Key Adder

A lightweight bash utility that simplifies adding SSH keys to the ssh-agent with clear feedback and error handling.

Features

  • 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

Installation

Download the script:

curl -o ~/bin/ssh-add-key https://raw.githubusercontent.com/your-username/ssh-key-adder/main/ssh-add-key

Make it executable:

chmod +x ~/bin/ssh-add-key

Add 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-key

Usage

Basic usage:

ssh-add-key ~/.ssh/id_rsa

Add key with Windows path (Git Bash):

ssh-add-key /c/Users/username/.ssh/my_github_key

Use environment variable:

export SSH_KEY_PATH=~/.ssh/id_ed25519
ssh-add-key

Show help:

ssh-add-key -h
# or
ssh-add-key --help

Examples

Add your default RSA key:

ssh-add-key ~/.ssh/id_rsa

Add an Ed25519 key for GitHub:

ssh-add-key ~/.ssh/id_ed25519

Add a custom key from Windows path:

ssh-add-key "C:\Users\username\.ssh\custom_key"

Troubleshooting

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 -l

ssh-agent not found

  • Install OpenSSH client:
    • Ubuntu/Debian: sudo apt install openssh-client
    • macOS: Already installed
    • Windows: Install Git Bash or Cygwin

Testing GitHub Connection

After adding your key, test it with GitHub:

ssh -T git@github.com

You should see:

Hi username! You've successfully authenticated...

Contributing

Contributions are welcome! Feel free to:

  • Report bugs via Issues
  • Submit feature requests
  • Open pull requests

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Yanin Vyacheslav

Support

If this script helped you, consider giving it a star on GitHub! ⭐

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages