streamline package naming

This commit is contained in:
Benjamin Diedrichsen
2026-07-29 13:07:34 +02:00
parent 1ba1c2a32a
commit 7e703c93b1
100 changed files with 141 additions and 139 deletions
@@ -0,0 +1,93 @@
# ssh-keygen
**Generate SSH key for a given user**
## Purpose
This cube generates a new SSH key pair for a specified user, which can be used for secure, passwordless authentication to remote servers and services like GitHub, GitLab, or other SSH-accessible systems.
## What are SSH Keys?
SSH keys provide a more secure and convenient way to authenticate compared to passwords:
- **Public key**: Shared with servers/services you want to access (like GitHub)
- **Private key**: Kept secret on your local machine, never shared
- **Passphrase-free**: This cube generates keys without a passphrase for automation
- **Algorithm support**: RSA (traditional) or Ed25519 (modern, recommended)
## What This Cube Does
1. Creates the `.ssh` directory with proper permissions (700)
2. Generates an SSH key pair using the specified algorithm
3. Saves the keys as `id_{SUFFIX}` and `id_{SUFFIX}.pub`
4. Logs the public key to the console for easy copying
## Configuration
### Parameters
- **SUFFIX** (string, default: `'ed25519'`)
- Suffix for keyname (e.g., `github``id_github.pub`)
- Helps identify the purpose of the key
- **EMAIL** (string, default: `'undefined@bitsquare.dev'`)
- Email address to associate with the SSH key
- Used as a comment in the public key
- **ALGORITHM** (enum: `'rsa'` | `'ed25519'`, default: `'ed25519'`)
- SSH key algorithm type
- **Ed25519**: Modern, faster, more secure (recommended)
- **RSA**: Traditional, widely supported
- **USER** (string, default: `'vagrant'`)
- Username for which to generate the SSH key
- Inherited from `user-add` dependency
## Dependencies
- **user-add** - Creates the user account first
## Post-Installation
After the key is generated:
1. The public key will be logged to the console
2. Copy the public key and add it to the target service:
- **GitHub**: Settings → SSH and GPG keys → New SSH key
- **GitLab**: Preferences → SSH Keys
- **Remote server**: Add to `~/.ssh/authorized_keys`
3. SSH config is automatically set up for the key
## Key Locations
- Private key: `/home/{USER}/.ssh/id_{SUFFIX}`
- Public key: `/home/{USER}/.ssh/id_{SUFFIX}.pub`
## Algorithm Comparison
**Ed25519** (Recommended):
- Smaller keys (256-bit)
- Faster generation and verification
- More secure against certain attacks
- Not supported on very old systems
**RSA**:
- Larger keys (2048-4096 bit)
- Universally supported
- Slower than Ed25519
- Well-tested and trusted
## Example Usage
Generate a key for GitHub access:
```javascript
exec('ssh-keygen', {
SUFFIX: 'github',
EMAIL: 'myemail@example.com',
ALGORITHM: 'ed25519',
USER: 'myuser'
})
```
This creates `id_github` and `id_github.pub` in `/home/myuser/.ssh/`.
@@ -0,0 +1,46 @@
from pyinfra.operations import files, server, python
from pyinfra import host, logger
import logging
NAME=host.data.SUFFIX
EMAIL=host.data.EMAIL
ALGORITHM=host.data.ALGORITHM
USER=host.data.USER
# Ensure the .ssh directory exists
files.directory(
name="Ensure .ssh directory exists",
path=f"/home/{USER}/.ssh",
present=True,
mode=700,
user=USER,
group=USER,
)
# Generate the SSH keypair
server.shell(
name=f"Generate SSH key id_{NAME}",
commands=[
f"ssh-keygen -t {ALGORITHM} -f /home/{USER}/.ssh/id_{NAME} -C '{EMAIL}' -N ''"
]
)
# Print the public key
result = server.shell(
name="Print public key",
commands=[f"cat /home/{USER}/.ssh/id_{NAME}.pub"],
)
def callback():
# 🔹 Extract and log the key output
if result.stdout:
logger.info(f"Public Key for {USER}: {result.stdout.strip()}")
else:
logger.warning(f"No public key found for {USER} at /home/{USER}/.ssh/id_{NAME}.pub")
python.call(
name="Log public key",
function=callback,
)
@@ -0,0 +1,20 @@
import { Manifest } from '@bitsquare/nopy-cubes';
import { z } from 'zod';
export default Manifest({
id: 'ssh:keygen',
name: 'Generate SSH key for a given $USER',
dependencies: () => ['user:add'],
schema: z.object({
SUFFIX: z
.string()
.describe('Suffix for keyname, e.g. github => id_github.pub')
.default('ed25519'),
EMAIL: z
.string()
.describe('Email address to associate with the SSH key')
.default('undefined@bitsquare.dev'),
ALGORITHM: z.enum(['rsa', 'ed25519']).describe('SSH key algorithm type').default('ed25519'),
USER: z.string().describe('Username for which to generate the SSH key').default('vagrant'),
}),
});