Skip to content

iamdanielv/ssh-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔑 SSH Manager

A user-friendly, interactive TUI for managing your ~/.ssh/config file.

About • Demo • Features • Installation • Quick-Actions

🧠 About

SSH Manager provides a simple and robust terminal interface for all your common SSH configuration tasks. It's designed to be a powerful alternative to manually editing your ~/.ssh/config file, reducing errors and saving time.

It is a single, self-contained bash script with no external dependencies beyond standard command-line tools, making it highly portable and easy to use anywhere.

Screens

Main view

+ SSH Manager
──────────────────────────────────────────────────────────────────────
   HOST ALIAS           user@hostname[:port] (key)
──────────────────────────────────────────────────────────────────────
 ❯ kvm                  [email protected]:223                           
   (~/.ssh/id_ed25519)                                  
   kube                 [email protected]                           
   [dev, test, kube] (~/.ssh/kube_id_ed25519)               
──────────────────────────────────────────────────────────────────────
  Host Actions: (A)dd | (D)elete | (C)lone           │ ? more options
  Host Edit:    (E)dit host details                  │ Q/ESC (Q)uit
  Filter:       (F)ilter by tag or alias
──────────────────────────────────────────────────────────────────────

Expanded Footer

──────────────────────────────────────────────────────────────────────
  Host Actions: (A)dd | (D)elete | (C)lone           │ ? fewer options
  Host Edit:    (E)dit host details                  │ Q/ESC (Q)uit
  Filter:       (F)ilter by tag or alias
  Manage:       SSH (K)eys | (P)ort Forwards
                (O)pen ssh config in editor
  Connection:   ENTER Connect | (t)est selected | (T)est all
  Navigation:   ↓/j Move Down | ↑/k Move up
──────────────────────────────────────────────────────────────────────

Add a New Host

+ Add New SSH Host
──────────────────────────────────────────────────────────────────────
Configure the new host:
  1)   Host (Alias)   : (not set)
  2)   HostName       : (not set)
  3)   User           : daniel
  4)   Port           : 22
  5)   IdentityFile   : (not set)
  6)   Tags           : (not set)

  c) (C)ancel/(D)eset fields
  s) (S)ave and Quit
  q) (Q)uit without saving (or press ESC)

[?] Your choice: 

Key Management

+ Key Management
──────────────────────────────────────────────────────────────────────
   KEY FILENAME              TYPE       BITS   COMMENT                
──────────────────────────────────────────────────────────────────────
 ❯ some_Name                 ED25519    256    @iamdanielv             
   server1                   ED25519    256    @iamdanielv   
   id_ed25519ssssssssssssss… ED25519    256    daniel@something…
   id_rsa                    RSA        3072   daniel@pop-os          
──────────────────────────────────────────────────────────────────────
  Key Actions:  (A)dd | (D)elete | (R)ename               │ Q/ESC Back
                (C)opy to server | (V)iew public | Re-gen (P)ublic
  Navigation:   ↓/j Move Down | ↑/k Move up
──────────────────────────────────────────────────────────────────────

Port Forwards

+ Saved Port Forwards
──────────────────────────────────────────────────────────────────────
   HOST                 FORWARD                                      
   [ ] PID      TYPE    DESCRIPTION                                  
──────────────────────────────────────────────────────────────────────
 ❯ dev.local            8081:localhost:80                            
   [-] off      Remote  web server on dev         
   kube.test            8082:localhost:80                            
   [-] off      Local   web server on kube
──────────────────────────────────────────────────────────────────────
  Actions:      (A)dd | (D)elete | (E)dit | (C)lone | ENTER Start/Stop
  Navigation:   ↓/j Move Down | ↑/k Move up              │ Q/ESC Back
──────────────────────────────────────────────────────────────────────

✨ Features

  • Responsive TUI: Terminal interface with:
    • Clean, aligned, table-like layouts for all lists.
    • Collapsible footers to maximize content visibility.
    • In-place actions (start/stop, delete) for a smooth, flicker-free workflow.
    • input validation to prevent configuration errors.
  • Tagging and Filtering:
    • Assign tags to hosts to organize them.
    • Filter the host list by tag or alias to quickly find what you need. The project is split into two scripts with distinct features:

ssh-manager.sh (Main Script)

The main script provides a TUI for all your common, day-to-day SSH tasks.

  • Server Management:
    • Interactively select a host and connect.
    • Add new hosts from scratch or by cloning an existing one.
    • Edit host parameters (alias, hostname, user, port, key file, tags) using a step-by-step wizard.
    • delete and clone hosts.
    • Test the connection to a single host or all hosts in parallel.
  • Key Management:
    • Generate new ed25519 or rsa key pairs.
    • delete and rename key pairs.
    • Copy public keys to a remote server using ssh-copy-id.
    • Re-generate a public key from a private key.
    • View public key contents.
  • Port Forwarding:
    • Save, manage, and activate port forward configurations (~/.ssh/port_forwards.conf).
    • View live status of active forwards.
    • add, edit, delete, and clone saved configurations.
  • Direct Config Editing:
    • A top-level menu option provides a shortcut to open your entire ~/.ssh/config file in your default $EDITOR.

advanced-ssh-manager.sh (Advanced Tools)

This script provides a focused TUI for more complex or potentially destructive operations, accessible via a separate command.

  • Advanced Editing: Open a specific host's entire configuration block in your $EDITOR.
  • Backup: Create a timestamped backup of your config file.
  • Import/Export: Export selected host configurations to a new file or import them from a file into your main config.
  • Host Management: The advanced view also allows for quick access to edit hosts in the editor, backup, import, and export.

🏷️ Tagging and Filtering

You can add tags to your hosts to organize them. Tags are stored as a comment in the host's configuration block:

Host my-server
    HostName 192.168.1.100
    User admin
    # Tags: web, production

To filter the hosts list, press f in the main view and enter a tag or part of a host's alias.

🚀 Quick Actions

Bypass the interactive menus for quick, direct actions.

ssh-manager.sh

  • -c, --connect: Go directly to host selection for connecting.
  • -a, --add: Go directly to the 'Add a new server' menu.
  • -p, --port-forward: Go directly to the 'Port Forwarding' menu.
  • -l, --list-hosts: List all configured hosts and exit.
  • -f, --list-forwards: List active port forwards and exit.
  • -t, --test [host|all]: Test connection to a specific host, all hosts, or show the selection menu.
  • -h, --help: Show the help message.

advanced-ssh-manager.sh

  • -h, --help: Show the help message.

📦 Installation

This project now consists of two scripts:

  • ssh-manager.sh: The main script for day-to-day server, key, and port-forwarding management.
  • advanced-ssh-manager.sh: A separate script for advanced tasks like backups, import/export, and direct file editing.
  1. Clone the repository:

    git clone https://github.com/iamdanielv/ssh-manager.git
    cd ssh-manager
  2. Build the standalone scripts: The source code is in the src/ directory. A build script is provided to bundle them into standalone executables.

    make build

    This will create the ssh-manager.sh and advanced-ssh-manager.sh executables in the dist/ directory.

  3. Run it:

    ./dist/ssh-manager.sh
    # or for advanced tools:
    ./dist/advanced-ssh-manager.sh

    For convenience, place it in a directory that is in your PATH (e.g., ~/.local/bin or /usr/local/bin) to run it from anywhere.

    # Example:
    sudo mv dist/ssh-manager.sh /usr/local/bin/ssh-manager
    ssh-manager # Now you can run it like this

🛠️ Development

This project uses a Makefile to streamline common development and build tasks. Run make or make help to see a list of all available commands.

Building

  • make build: Builds the standalone, distributable scripts in the dist/ directory. This is the recommended way to create the final executables.
  • make clean: Removes the dist/ directory and other build artifacts.

Testing

  • make test: Runs the entire test suite located in the test/ directory.

Running Scripts

You can run the scripts in two ways:

  1. Development Mode: Run the scripts directly from the src/ directory. This is useful for quick testing during development as it doesn't require a build step.

    make ssh-manager
    make advanced-ssh-manager
    make playground
  2. Distribution Mode: Build and then run the final standalone scripts. This is how an end-user would run them.

    make dist-ssh-manager
    make dist-advanced-ssh-manager

⚙️ Dependencies

The script relies on a set of common command-line tools that are pre-installed on most Linux and macOS systems:

ssh, ssh-keygen, ssh-copy-id, awk, cat, grep, rm, mktemp, cp, date

🤝 Contributing

I'm open to and encourage contributions of bug fixes, improvements, and documentation!

📜 License

MIT License - See the LICENSE file for details.

📧 Contact

Let me know if you have any questions.

About

An interactive TUI for managing and connecting to SSH hosts defined in ~/.ssh/config.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published