Generate an SSH key and add it to GitHub — with clear steps, or fully automated via the GitHub API.
Project description
gh-ssh-setup
Generate an SSH key on your machine and add it to GitHub — either with clear, copy-paste steps, or fully automated through the GitHub REST API.
- 🔐 Pure-Python key generation (Ed25519 by default, RSA optional) via
cryptography— no externalssh-keygenrequired. - 📋 Prints every manual step (ssh-agent, copy public key, add on GitHub, test).
- 🤖 One command to generate + upload + verify, end to end.
- 🛡️ Private key written
0600; only the public key ever leaves your machine.
Install
pip install gh-ssh-setup
From source:
git clone https://github.com/rghosh08/gh-ssh-setup
cd gh-ssh-setup
pip install -e .
Usage
1. Generate a key and see the manual GitHub steps
gh-ssh-setup generate --email you@example.com
This creates ~/.ssh/id_ed25519 + ~/.ssh/id_ed25519.pub and prints the exact
steps to register it at https://github.com/settings/ssh/new.
2. Full automation (generate → upload → test)
Create a GitHub Personal Access Token with the admin:public_key
(write:public_key) scope at https://github.com/settings/tokens, then:
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxx
gh-ssh-setup setup --email you@example.com --title "my-laptop"
Output:
✔ Authenticated to GitHub as yourname
✔ Generated ed25519 key
✔ Added key 'my-laptop' to GitHub (id=123456789)
→ Testing: ssh -T git@github.com
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.
Other commands
gh-ssh-setup upload --key-path ~/.ssh/id_ed25519.pub --title "existing-key"
gh-ssh-setup list # show keys already on your GitHub account
gh-ssh-setup test # run ssh -T git@github.com
Run gh-ssh-setup <command> --help for all flags (--type rsa, --passphrase,
--overwrite, --key-path, --no-agent, ...). setup/generate also print an
optional ~/.ssh/config block and load the key into ssh-agent for you (skip with
--no-agent).
Use as a library
from gh_ssh_setup import generate_key_pair, upload_key_to_github, manual_steps
kp = generate_key_pair(comment="you@example.com")
print(manual_steps(kp)) # copy-paste steps
upload_key_to_github(kp.public_key, title="laptop") # or automate it
GitHub MCP (agentic automation)
If you drive this from an agent that has the GitHub MCP server connected,
you can skip the token plumbing and let the agent call the equivalent MCP tool
to create the key (POST /user/keys). This package still does the key
generation locally (the private key must never leave your machine); the MCP
only handles the public-key upload. Point your agent at:
- Generate locally:
gh-ssh-setup generate(orgenerate_key_pair()). - Upload via MCP: call the GitHub MCP "create SSH signing/auth key" tool with
the
.pubcontents, or just usegh-ssh-setup setupwith a token.
Security notes
- The private key (
id_ed25519) is secret. This tool writes it0600and never transmits it. Only the.pubfile is uploaded. - Prefer a short-lived, minimally-scoped PAT (
admin:public_keyonly). - Consider a
--passphrasefor defense in depth on shared machines.
Development
A Makefile wraps the common tasks (make help to list them):
make dev # pip install -e ".[dev]"
make test # pytest
make build # sdist + wheel into dist/
make check # twine check dist/*
CI runs on every push/PR (Python 3.8–3.12). Pushing a vX.Y.Z tag publishes to
PyPI automatically via Trusted Publishing — see PUBLISHING.md.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gh_ssh_setup-0.1.0.tar.gz.
File metadata
- Download URL: gh_ssh_setup-0.1.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88dabf673f5c5df868b0ba4cb55a0276f497d58cdb2cc67569c018f188fe9453
|
|
| MD5 |
7f39344dd19d55dd5f1e7a38f1dc1640
|
|
| BLAKE2b-256 |
6cf4f2fa75ccf5cb7daa52d3d66d69fb1dc205946643bb636fb4155fd997bb3e
|
Provenance
The following attestation bundles were made for gh_ssh_setup-0.1.0.tar.gz:
Publisher:
publish.yml on rghosh08/gh-ssh-setup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_ssh_setup-0.1.0.tar.gz -
Subject digest:
88dabf673f5c5df868b0ba4cb55a0276f497d58cdb2cc67569c018f188fe9453 - Sigstore transparency entry: 2112424928
- Sigstore integration time:
-
Permalink:
rghosh08/gh-ssh-setup@4dce83e124f261df24205b38f848c3eb710d8ac1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rghosh08
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4dce83e124f261df24205b38f848c3eb710d8ac1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gh_ssh_setup-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gh_ssh_setup-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc5808937e29ab85168962191089870fec5fb5073592810396e429b2fc93c656
|
|
| MD5 |
da7bfd46927dd1d74ff9f00c628d09c7
|
|
| BLAKE2b-256 |
924a090f2999bb783357cf1b6c7e599efe7af3ec408bedc2d6a95e2964767295
|
Provenance
The following attestation bundles were made for gh_ssh_setup-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on rghosh08/gh-ssh-setup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_ssh_setup-0.1.0-py3-none-any.whl -
Subject digest:
bc5808937e29ab85168962191089870fec5fb5073592810396e429b2fc93c656 - Sigstore transparency entry: 2112424951
- Sigstore integration time:
-
Permalink:
rghosh08/gh-ssh-setup@4dce83e124f261df24205b38f848c3eb710d8ac1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rghosh08
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4dce83e124f261df24205b38f848c3eb710d8ac1 -
Trigger Event:
push
-
Statement type: