Skip to content

alminisl/krakncat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

krakncat Logo

krakncat

πŸ™ A simple CLI tool to manage multiple GitHub accounts on your machine.

krakncat (or krakn) helps you generate SSH keys, configure git and SSH for each account, and easily switch between accounts when working with repositories.

Features

  • πŸ”‘ Generate SSH keys per account with automatic SSH config setup
  • πŸ‘₯ Add multiple GitHub accounts with personalized configuration
  • πŸ“ Manage git user/email settings per project directory
  • πŸ”„ Clone repositories using the right SSH key and account
  • 🎯 Simple commands with an intuitive CLI interface

Installation

Prerequisites

Ensure you have Go 1.21+ installed on your system.

Arch Linux:

sudo pacman -S go

Other distributions:

Build from source

git clone https://github.com/alminisl/krakncat.git
cd krakncat
make dev              # Download deps, tidy modules, and build

Alternative build methods

Using Go directly:

go mod tidy
go build -o krakn .

Using make:

make build           # Just build
make install         # Build and install to /usr/local/bin
make test           # Run tests
make clean          # Clean build artifacts

Installation to system

# After building
sudo cp krakn /usr/local/bin/
# or use make
make install

Quick Install for Arch Linux πŸƒβ€β™‚οΈ

git clone https://github.com/alminisl/krakncat.git
cd krakncat
./install-arch.sh    # Automated installation script

This script will:

  • Install Go and other dependencies via pacman
  • Build the application
  • Optionally install it system-wide

First Run - Smart Migration πŸ†•

When you run krakncat for the first time, it automatically detects ALL existing configurations and lets you choose what to import:

./krakn list
# πŸ‘‹ Welcome to krakncat!
# πŸ” I found existing git/SSH configuration:
#
#    1. Global Git Config - Name: John Doe - Email: john@example.com (recommended)
#    2. SSH Config (github.com-work) - Username: john-work
#    3. SSH Config (github.com-personal) - Username: john-personal
#
# πŸ’« Would you like to migrate any of these accounts to krakncat? [Y/n]:
# πŸ“‹ Select accounts to migrate:
#    0. Skip migration
#    1. Global Git Config (recommended)
#    2. SSH Config (github.com-work)
#    3. SSH Config (github.com-personal)
#    4. Migrate all
#
# Enter your choice(s) separated by commas (e.g., 1,3): 1,2

Smart Migration Features:

  • πŸ” Auto-Detection: Finds existing git config AND SSH configurations
  • 🎯 Multi-Account: Detects multiple GitHub accounts from SSH config
  • ✨ Selective Import: Choose exactly which accounts to migrate
  • πŸ”‘ SSH Key Matching: Automatically suggests appropriate SSH keys
  • πŸ“ Custom Naming: Rename accounts during migration
  • πŸš€ Zero Setup: Creates complete account configurations instantly

Requirements

  • Go 1.24+
  • Git
  • SSH (ssh-keygen, ssh-agent)

Usage

Generate a new SSH key for an account

./krakn generate-key --name personal --email your.email@example.com

This command:

  • Creates a new ED25519 SSH key pair
  • Saves it as ~/.ssh/id_ed25519_gh_<name>
  • Optionally adds SSH config to ~/.ssh/config
  • Displays the public key for you to add to GitHub
  • Optionally saves the account configuration for easy switching

Add a new GitHub account

./krakn add

Interactive command that prompts for:

  • Account name (e.g., 'work', 'personal')
  • Email address
  • GitHub username
  • SSH key path (with option to generate if missing)

List all accounts

./krakn list
# or
./krakn ls

Shows:

  • All configured accounts with details
  • Current active account (marked with βœ…)
  • Current git configuration (local and global)

Switch accounts

# Switch globally
./krakn use personal

# Switch for a specific repository
./krakn use work /path/to/repo

This command:

  • Updates git user.name and user.email configuration
  • Works globally or for specific repositories
  • Shows which SSH host to use for cloning

Automatic Directory-Based Configuration (Git Conditional Includes)

🎯 The most powerful feature! Set up automatic account switching based on directory location.

# Set up automatic config for a directory
./krakn config ~/work/projects work
./krakn config ~/personal/projects personal

# Or configure current directory interactively
cd ~/work/my-project
./krakn config

This uses Git's conditional includes feature to automatically use the right account when you cd into different directories!

Set Global Default

# Set global default account
./krakn global personal

View Configuration

# Show current conditional includes
./krakn show-includes

# Show only global git config (quick check)
./krakn list --global

Migration and Account Management

# Manually trigger migration of existing git/SSH config
./krakn migrate

# Remove an account when no longer needed
./krakn remove old-account

Advanced Migration Features:

  • πŸ” Smart Detection: Automatically finds all GitHub configurations (git config + SSH hosts)
  • 🎯 Multi-Account Support: Import multiple accounts in one session
  • ✨ Selective Migration: Choose exactly which accounts to migrate
  • πŸ”‘ SSH Key Selection: Pick from existing keys or generate new ones
  • πŸ“ Account Renaming: Customize account names during migration
  • πŸš€ Batch Import: Migrate all detected accounts with one command

Example output:

βœ… Switched to account 'personal' globally
πŸ‘€ Name: johndoe
πŸ“§ Email: john@example.com
πŸ”— SSH Host: github.com-personal

πŸ’‘ To clone repositories with this account, use:
   git clone git@github.com-personal:username/repo.git

SSH Configuration

When you generate a key, krakncat can automatically add an SSH config entry like this:

Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gh_personal

This allows you to use different SSH keys for different accounts by using the host alias:

git clone git@github.com-personal:username/repo.git

Commands

Command Description
generate-key Generate and configure a new SSH key for any Git provider
add Add a new Git account (GitHub, GitLab, Gitea, or custom) with interactive prompts
list / ls List all configured accounts grouped by provider and current git configuration
use Switch git configuration to use a specific account (globally or per-repo)
config Setup automatic git config for a directory using conditional includes
global Set global git configuration to use a specific account
show-includes Show current conditional includes in global git config
migrate Migrate existing git configuration to krakncat (supports all providers)
remove Remove a Git account configuration
help Show help for any command

Key Flags

  • list --global / list -g: Show only global git configuration
  • use [account] [path]: Switch account globally or for specific repository

Flags for generate-key

  • --name (required): Unique account name (e.g., 'work', 'personal')
  • --email (required): Email address for the SSH key
  • --help: Show help for the command

Arguments for use

  • account-name (required): Name of the account to switch to
  • path (optional): Repository path for local configuration (omit for global)

Example Workflow

Option 1: Manual Switching (Traditional)

  1. Generate SSH keys and add accounts:

    # Add work account
    ./krakn generate-key --name work --email work@company.com
    # Follow prompts to save account configuration
    
    # Add personal account
    ./krakn add
    # Follow interactive prompts
  2. Switch between accounts as needed:

    # Switch globally to work account
    ./krakn use work
    
    # Switch just for a specific project
    ./krakn use personal ~/my-personal-project
  3. Add the public keys to your GitHub accounts:

  4. Clone repositories using the appropriate account:

    # For work account
    git clone git@github.com-work:company/project.git
    
    # For personal account
    git clone git@github.com-personal:username/personal-project.git

Option 2: Automatic Directory-Based Switching (Recommended! 🌟)

  1. Set up accounts and directory structure:

    # Add accounts (same as above)
    ./krakn generate-key --name work --email work@company.com
    ./krakn add  # for personal
    
    # Set global default
    ./krakn global personal
    
    # Set up automatic switching for work directory
    ./krakn config ~/work work
  2. Now it's completely automatic:

    cd ~/work/any-project        # Automatically uses work account
    git config user.email        # Shows: work@company.com
    
    cd ~/personal/my-project     # Automatically uses personal account
    git config user.email        # Shows: personal@gmail.com

How It Works: Git Conditional Includes

Behind the scenes, krakncat modifies your ~/.gitconfig to include:

[user]
    name = Personal Name
    email = personal@gmail.com

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

And creates ~/work/.gitconfig:

[user]
    name = Work Name
    email = work@company.com

This means:

  • Default: Personal account everywhere
  • In ~/work/: Work account automatically
  • No manual switching needed! πŸŽ‰

Account Storage

krakncat stores account configurations in ~/.krakncat/config.json. This file contains:

  • Account details (name, email, username, SSH key path)
  • Current active account
  • Account-specific settings

The configuration is automatically created when you add your first account.

Project Structure

krakncat/
β”œβ”€β”€ main.go              # Entry point
β”œβ”€β”€ go.mod               # Go module definition
β”œβ”€β”€ go.sum               # Go module checksums
β”œβ”€β”€ README.md            # This file
└── cmd/
    β”œβ”€β”€ root.go          # Root command definition
    β”œβ”€β”€ krakn.go         # generate-key command implementation
    β”œβ”€β”€ add.go           # add command implementation
    β”œβ”€β”€ list.go          # list command implementation
    β”œβ”€β”€ use.go           # use command implementation
    β”œβ”€β”€ directory.go     # config command implementation
    β”œβ”€β”€ global.go        # global and show-includes commands
    β”œβ”€β”€ migrate.go       # migrate command implementation
    β”œβ”€β”€ remove.go        # remove command implementation
    └── config.go        # Configuration management

Upcoming Features

🚧 The following features are planned for future releases:

Multi-Provider Support (v2.0) 🌐

  • βœ… GitHub, GitLab, Gitea support - Add accounts from multiple Git hosting providers
  • βœ… Custom Git hosts - Support for self-hosted Git servers
  • βœ… Provider-specific configurations - Automatic SSH config generation per provider
  • βœ… Unified account management - Manage all providers through the same interface

Enhanced Commands

  • clone - Clone repositories using the correct SSH key automatically (provider-aware)
  • edit - Edit account details including switching providers
  • backup - Backup/restore account configurations with provider info
  • clean - Remove orphaned conditional includes from .gitconfig
  • providers - List and manage supported Git hosting providers

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.

Troubleshooting

Build Issues

Error: "found packages cmd and main"

  • This occurs when there are duplicate files. Ensure there's no krakn.go in the root directory.
  • Solution: Remove any duplicate files and rebuild.

Error: "go: command not found"

Error: Module download issues

  • Check your internet connection and Go proxy settings.
  • Try: go env -w GOPROXY=direct

Runtime Issues

Error: "ssh-keygen: command not found"

  • OpenSSH is not installed.
  • Arch Linux: sudo pacman -S openssh

Permission denied accessing SSH files

  • Ensure proper permissions on ~/.ssh/ directory: chmod 700 ~/.ssh
  • SSH key files should have 600 permissions: chmod 600 ~/.ssh/id_*

Error: "No such file or directory" when generating SSH keys

  • This usually means the .ssh directory doesn't exist.
  • krakncat automatically creates it, but if you see this error, manually create it:
    mkdir -p ~/.ssh
    chmod 700 ~/.ssh

SSH key generation fails with "exit status 1"

  • Check if the SSH key path directory exists and is writable
  • Ensure you have sufficient disk space
  • Try generating the key manually first: ssh-keygen -t ed25519 -f ~/.ssh/test_key

Git config not working

  • Check if Git is installed: git --version
  • Verify config with: git config --list

Getting Help

  • Run krakn --help for command overview
  • Run krakn <command> --help for specific command help
  • Check existing SSH configs: cat ~/.ssh/config
  • View current Git config: git config --global --list

Multi-Provider Support 🌐

krakncat supports multiple Git hosting providers:

  • GitHub (github.com)
  • GitLab (gitlab.com)
  • Gitea (gitea.com or self-hosted)
  • Custom Git hosts (any Git server)

Adding accounts for different providers

# Add a GitHub account
./krakn add
# 🌐 Select Git hosting provider:
#    1. GitHub (github.com)
#    2. GitLab (gitlab.com)
#    3. Gitea (gitea.com)
#    4. Custom/Self-hosted (e.g., git.company.com, code.myorg.io)
# Enter choice (1-4): 1

# Add a GitLab account  
./krakn add
# Select option 2 for GitLab

# Add a self-hosted Gitea account
./krakn add  
# Select option 4 for custom
# Enter hostname: git.company.com
# Enter display name: Company Gitea
# SSH user [git]: git
# SSH port [22]: 2222
# SSH key management URL: https://git.company.com/user/settings/keys

Multi-Provider SSH Configuration

krakncat automatically generates provider-specific SSH configurations:

# GitHub accounts
Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gh_personal

Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gh_work

# GitLab accounts  
Host gitlab.com-freelance
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gl_freelance

# Self-hosted Gitea
Host git.company.com-work
  HostName git.company.com
  User git
  IdentityFile ~/.ssh/id_ed25519_company_work

# Custom port example  
Host code.internal.com-dev
  HostName code.internal.com
  User git
  Port 2222
  IdentityFile ~/.ssh/id_ed25519_internal_dev

Cloning from different providers

# GitHub
git clone git@github.com-personal:username/repo.git

# GitLab
git clone git@gitlab.com-freelance:username/project.git

# Self-hosted Gitea
git clone git@git.company.com-work:team/internal-tool.git

Provider-specific features

  • Automatic key naming: Keys are prefixed with provider (gh_, gl_, gitea_, custom_)
  • Provider-specific URLs: Direct links to SSH key management pages
  • Custom hostnames: Support for any self-hosted Git server
  • Unified management: All providers managed through the same commands

Advanced Custom Provider Features

Smart hostname handling:

  • Automatic key suffix generation (git.company.com β†’ company)
  • Support for any domain, subdomain, or IP address
  • Custom SSH port configuration
  • Flexible SSH user settings

Common custom setups supported:

  • Self-hosted GitLab: gitlab.company.com
  • Self-hosted Gitea: git.myorg.io
  • Bitbucket Server: bitbucket.enterprise.com:7999
  • Azure DevOps Server: tfs.company.com
  • Custom Git servers: code.internal.net

Example custom provider configuration:

./krakn add
# πŸ”§ Custom Git Provider Setup
# 🌐 Enter hostname: git.company.com
# πŸ“ Enter display name [git.company.com]: Company Git
# πŸ‘€ SSH user [git]: git  
# πŸ”Œ SSH port [22]: 2222
# πŸ”— SSH key management URL: https://git.company.com/settings/ssh
# πŸ”‘ SSH key suffix will be: company
# 
# βœ… Custom provider configuration:
#    Name: Company Git
#    Hostname: git.company.com
#    SSH User: git
#    SSH Port: 2222
#    Web URL: https://git.company.com/settings/ssh
#    Key Suffix: company

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages