Skip to main content

A tool for parsing and displaying SSH connection history

Project description

SSH Shortcut Manager

SSH Shortcut Manager is a Python-based tool to manage and connect to SSH sessions using shortcuts. It supports both interactive and command-line modes, allowing you to assign shortcuts to SSH commands and use them directly in your terminal. The tool automatically adds these shortcuts as aliases in your shell (~/.bashrc and ~/.zshrc), making them available across sessions.

Features

  • Interactive Mode:

    • Search and filter SSH connections.
    • Assign or edit shortcuts for SSH sessions.
    • Directly connect to SSH sessions from the interactive UI.
  • Command-Line Mode:

    • Use shortcuts directly from the terminal (e.g., sshmgm --shortcut tp-1).
  • Shell Alias Management:

    • Automatically creates or updates aliases in ~/.bashrc and ~/.zshrc.
    • Ensures the aliases persist across sessions.
  • Dynamic Management:

    • Prevents duplicate shortcuts.
    • Replaces existing shortcuts in shell configurations.

Installation

Prerequisites

  • Python 3.7 or higher
  • Pip (Python package manager)
  • Bash or Zsh shell

Steps

  1. Clone the repository:

    git clone https://github.com/htayanloo/SSH-Manager.git
    cd SSH-Manager
    
  2. Install the package:

    pip install .
    
  3. Verify the installation:

    sshmgm --help
    

Usage

asciicast

Interactive Mode

Run the tool interactively:

sshmgm

Features in Interactive Mode

  • Search (s): Search for SSH connections by keywords.
  • Select (number): Select an SSH connection to connect or edit its shortcut.
  • Shortcut (sc): Directly connect using a shortcut.
  • Back (b): Return to the full list.
  • Quit (q): Exit the tool.

Shortcut Options

  • Connect (c): Start an SSH session for the selected item.
  • Set Shortcut (ss): Assign or update a shortcut for the selected session.

Command-Line Mode

Run the tool with a shortcut directly from the terminal:

sshmgm --shortcut <shortcut>

Example:

sshmgm --shortcut tp-1

Shell Alias Management

When you assign a shortcut, the tool automatically creates or updates an alias in your shell configuration files (~/.bashrc and ~/.zshrc).

  • Example alias added to ~/.bashrc and ~/.zshrc:

    alias tp-1='ssh user@192.168.1.1'
    
  • Run the alias directly in the terminal:

    tp-1
    

The tool ensures existing aliases are replaced and configurations are reloaded, making the shortcuts available immediately.

Configuration Files

Session Data

SSH session data is stored in ~/.autossh/ssh_connections.json. This file is managed automatically by the tool.

Example structure:

[
    {
        "server_ip": "192.168.1.1",
        "user": "root",
        "port": "22",
        "type": "default",
        "raw_command": "ssh root@192.168.1.1",
        "shortcut": "tp-1",
        "source_file": "bash_history"
    },
    {
        "server_ip": "192.168.1.2",
        "user": "admin",
        "port": "22",
        "type": "proxy",
        "raw_command": "ssh admin@192.168.1.2",
        "shortcut": "srv2",
        "source_file": "zsh_history"
    }
]

Shell Configuration

The tool updates your shell configuration files (~/.bashrc and ~/.zshrc) to include aliases for each shortcut.

Examples

Setting a Shortcut

  1. Assign tp-1 to ssh root@192.168.1.1 in interactive mode.
  2. Run the alias:
    tp-1
    

Connecting with a Shortcut

  1. Use the command-line mode to connect:
    sshmgm --shortcut tp-1
    

Replacing a Shortcut

  1. Update the shortcut in interactive mode.
  2. The alias in ~/.bashrc and ~/.zshrc is automatically replaced.

Development

Run Locally

To test and run the project locally:

python -m autossh.ssh_manager

Add a New Feature

  1. Fork and clone the repository.
  2. Create a new branch:
    git checkout -b feature/new-feature
    
  3. Make your changes and submit a pull request.

Requirements

  • Python 3.7+
  • Bash or Zsh shell
  • Dependencies (installed via pip):
    • rich

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Developed by Hadi Tayanloo. Contributions are welcome! 😊

SSH-Manager

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sshmgm-1.0.3.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sshmgm-1.0.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file sshmgm-1.0.3.tar.gz.

File metadata

  • Download URL: sshmgm-1.0.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for sshmgm-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ff833f513a87d37ebeb71e3db8dd92ced662aae1e95242dad504f742ecc26fc8
MD5 2faa1e9b55a808d2ec3f33e4e8669f7e
BLAKE2b-256 6c7c2591e5e8e5f29c6a9eb865ea766e4ddf4bc0700d1bfe6e86bdd657fae5db

See more details on using hashes here.

File details

Details for the file sshmgm-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: sshmgm-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for sshmgm-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8446f0ca6917116fd9b4d0c8b093dcf1869bcc82762a3e5e05320c7986fe1c5
MD5 bd959795fa7ac870cf0176149065e271
BLAKE2b-256 dfb08f97082fbbbcd62d9d3016885103bd31f4684c1b47aac8593f371453868b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page