GHKeyFetch is a flexible Bash script designed to securely fetch and manage SSH public keys from a specified GitHub user. It allows you to update your authorized_keys
file by either adding new keys or replacing existing ones, with options for quiet, default, and verbose modes.
- Fetch Public SSH Keys: Automatically download public SSH keys from any GitHub user profile.
- Add or Replace Keys: Choose to append new keys to the existing
authorized_keys
file or replace the entire file. - Deduplication: Automatically removes duplicate keys when adding new keys.
- Flexible Output:
- Default Mode: Outputs the number of keys added.
- Quiet Mode: Suppresses all output, returning only exit codes.
- Verbose Mode: Provides detailed step-by-step output for debugging or monitoring purposes.
- Secure Temporary File Handling: Ensures all temporary files are securely managed and cleaned up after execution.
- Exit Codes: Returns
0
on success and1
on failure, suitable for use in automated systems.
- Bash
curl
orwget
installed on your system
Clone this repository to your local machine:
git clone https://github.com/yourusername/GHKeyFetch.git
cd GHKeyFetch
Make the script executable:
chmod +x ghkeyfetch.sh
Run the script with the desired options:
./ghkeyfetch.sh <github-username> [-c|--confirm] [-a|--add] [-q|--quiet] [-v|--verbose]
<github-username>
: The GitHub username to fetch the public keys from.-c, --confirm
: Confirm and execute the update to theauthorized_keys
file.-a, --add
: Add the fetched keys to the existingauthorized_keys
file, rather than replacing it.-q, --quiet
: Run the script in quiet mode, suppressing all output.-v, --verbose
: Run the script in verbose mode, providing detailed output.
-
Replace Existing Keys:
./ghkeyfetch.sh octocat -c
-
Add New Keys to Existing File and Remove Duplicates:
./ghkeyfetch.sh octocat -c -a
-
Run in Quiet Mode (No Output):
./ghkeyfetch.sh octocat -c -q
-
Run in Verbose Mode (Detailed Output):
./ghkeyfetch.sh octocat -c -v
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request if you have suggestions or improvements.
This script was inspired by the need to efficiently manage SSH keys from GitHub across multiple servers and environments. Thank you to the open-source community for providing the tools and inspiration to create this utility.