Giter Club home page Giter Club logo

hssh's Introduction



A CLI to easily list, search and connect to SSH hosts. Sync down hosts from providers in order to get a centralized hosts configuration.





Install

Add Homebrew Beliven tap with:

  brew tap beliven-it/tap

Then install hssh CLI with:

  brew install hssh





Configuration

Run hssh init to generate config file inside ~/.config/hssh/config.yml (works only if not exists yet) or let the CLI creating it automatically on first run (every command).

Right now the CLI supports the following providers:

  • GitLab
  • GitHub



Providers

Provide at least one connection string to a provider to start using the CLI. You can use more providers at the same time. Replace values as reported below.


  • PROVIDER is the provider name, like github or gitlab.
  • ACCESS_TOKEN is the provider access token. Required only for private projects/repositories.
  • ENTITY_ID is the reference to the project/repository where the files are stored. For GitLab is the project ID, you can find it under the project name (eg. 7192789). For GitHub is the name of the repository (eg. beliven-it/hssh).
  • SUBPATH is the path to the folder inside the project/repository where config files are saved. This parameter is optional, if you want to store hosts files inside the root of the project/repository, you can delete the @ and everything after it in the connection string.

You can also provide a structured version of the provider configuration in the following format:

providers:
  - type: gitlab
    url: "https://gitlab.com/api/v4"
    access_token: gpat-123456789
    entity_id: 9999
    subpath: "path/to/folder"
  - type: gitlab
    url: "https://git.my-domain.com/api/v4"
    access_token: mydingpat-123444444
    entity_id: 11
    subpath: "path"

NOTE

You cannot have the two providers configuration in different format. Make sure to use or the structured version, or the string version.



fzf options

See the man page (man fzf) for the full list of available options and add the desired ones to the fzf_options string inside ~/.config/hssh/config.yml. See more about the fzf options in the official repository.



Config file example

This is a complete config file example with two providers:

# HSSH configuration file
fzf_options: "-i"
providers:
  - "gitlab://my_access_token:/7192789@folder"
  - "github://my_access_token:/beliven-it/hssh"

Provider project/repository example

Project/repository example structure with subfolder:

  project/repository
  └── folder
      ├── file1
      └── file2

Project/repository example structure without subfolder:

  project/repository
  ├── file1
  └── file2

SSH host example to put inside hosts files:

  Host test
    Hostname 1.2.3.4
    User root
    Port 22
    IdentityFile ~/ssh/id_rsa





Usage

To see available commands and options, run: hssh, hssh help, hssh --help or hssh -h.





Development

Clone the repository and run inside the folder:

  • go mod init hssh
  • go mod vendor
  • go build -ldflags="-X hssh/cmd.Version=1.0.0"

Run ./hssh inside the folder to test the CLI.





Have found a bug?

Please open a new issue here.





Mentions

  • dmitri13 for the icon of the terminal used in the banner image





License

Licensed under MIT

hssh's People

Contributors

beliven-fabrizio-gortani avatar beliven-valentino-cossar avatar casvaldot avatar dependabot[bot] avatar valentinocossar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

valentinocossar

hssh's Issues

Host settings in case insensitive

Sometimes it happens that some connections attributes like 'Hostname' are inserted as 'HostName'.
To avoid problems it is better to convert attribute to lowercase.

HostName -> hostname
Hostname -> hostname

Using Host with multiple alias hssh is unable to connect

Hello!,
when my ssh config has multiple aliases in Host declaration, hssh fails to connect,
this is an example:

    Hostname 1.2.3.4
    Port 22
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null
    User root
    IdentityFile ~/.ssh/id_rsa

Status of connection

Can you make sense to set up a flag to apply a control over the connection status? I have a lot of hosts I don't have access, it would be nice to know what I can connect and to what not, what do you think?

An example could be:

hssh l --status-ok

The functions for each host perform a test connection and print the only available host.

Add example config file in README

Add example config file in README to allow simple copy/paste if someone doesn't want to rely on the config file auto-creation feature.

The comments with space indentation are not removed

In this case:

# HSSH start managed
Include config.hssh.d/*
# HSSH end managed
Host Test
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa
    # Enable agent forwarding
    # ForwardAgent yes
    # Forces OpenSSH to use only the key declared in the IdentityFile to connect to the various
    # https://man.openbsd.org/ssh_config.5#IdentitiesOnly
    # IdentitiesOnly yes

Only the first two comments are deleted. This produce a format error during listing as you can see in the screenshot above.

@: # Forces OpenSSH to use only the key declared in the to connect to the various

Daemon for automatic sync

It may also be useful to set up a command / flag that launches the background application and dealing with the sync of the data remotely.

hssh -d

or

hsshd

Remove wildcard host from fzf hosts list

Remove wildcard host from fzf hosts list. This kind of host is not for a single connection but to set config options for all hosts, so we can fix this by ignoring every host with a wildcard in the name.
image

Inconsistent parsing results

Sometimes the list of results of the command hssh l are not the same. This problem is related to invalid use of gorutines and channel inside the list controller. Maybe is better to reduce the complexity of this part into a simple one.

Add multi-provider logic

Add multi-provider logic with support for more than one provider at the same time, this allows to pull hosts from more than one source.

Tip: pay attention to file conflicts inside config.hssh.d folder, prepend config files name with provider.file-name or add a provider sub folder logic.

Sync twice if running hssh s

If you have the folder config.hssh.d empty, and you run hssh s the sync command run twice, because the system first perform the automatic sync (it occurred when the folder is empty) and then execute the sync command. Maybe the best way to resolve this problem is to disable the automatic sync and notify the user to run the sync command manually

Sync is inconsistent

It seems that running the sync command using goroutines sometimes cause the random elimination of some host files.
Maybe is better slow it down but more consistent.

Delete old synced folder before a new sync

Because a folder could have old files inside, an improvement could be deleting synced folder before redownloading it. This fixes a current issue with the new multi-provider function and the new file naming convention (eg. test.gitlab) that causes duplicated files: the older ones (pre multi-provider) and the new ones (post multi-provider) that are equal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.