Quickly connect to host entries from your SSH config file
Project description
SSH-Hosts
Simple script to list all host entries in your SSH configuration. You can then choose to quickly connect to one or more of them. This is handy if you organize a bunch of host entries in your SSH client config like, e.g.:
# Including files is also supported
Include /path/to/my/other/config/file
Host foo
Hostname foohost
User foouser
IdentityFile fookey
Host bar
Hostname barhost
User baruser
IdentityFile barkey
Notes:
- It is also possible to use wildcards in your SSH client config to set values for multiple hosts at once. This script will not show these entries, since they cannot be used to connect to a host directly.
Installation
- Install from pypi:
pip install ssh-hosts
OR
- Download the pip package from GitLab
- Install it with pip, e.g. pip install sshhosts-0.4.0-py3-none-any.whl
Basic usage
Just run
ssh-hosts
Running with no arguments will read in your ssh configuration from ~/.ssh/config
and list all found host entries. Type the number of an entry to connect to that given host.
Command line arguments overview
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-c CONFIG, --config CONFIG
Path to configuration file
-e EXCLUDE, --exclude EXCLUDE
Exclude hosts based on python regular expression
-s SSH_COMMAND, --ssh_command SSH_COMMAND
SSH command
-l, --loop Do not exit when ssh session ends, show host list again instead
-t, --terminal_tab_mode
Attempt to start ssh session in new tab/window of terminal
-o, --sort_host_entries
Sort host entries
-r, --reverse_order Reverse sorting order
-g, --gui Use a curses-like input dialog
Arguments
Path to SSH configuration
ssh-hosts -c '<path to ssh config>'
This will read in the SSH configuration file from the given path instead of ~/.ssh/config
.
Excluding hosts
ssh-hosts -e '<python regex>'
You can exclude host entries from the list based on a Python regular expression which needs to match exactly.
e.g.
ssh-hosts -e 'foo'
Will only exclude a host named 'foo', but not one named 'foo1'. To exclude both 'foo' and 'foo1' you could use
ssh-hosts -e 'foo\w*'
...or any other appropriate Python regular expression.
Using a custom ssh command
ssh-hosts -s '<shell/ssh command>'
You can supply a custom command which ssh-hosts will use when you pick a host. The default is just 'ssh'.
Examples:
Start ssh connection with debug output
ssh-hosts -s 'ssh -v'
Terminal tab mode
Experimental.
Tries so start ssh connections in new tabs if running in Windows Terminal, or in new windows when running in tmux.
ssh-hosts --terminal_tab_mode
You can combine this with loop
mode to keep the list of hosts open on one tab/window of your terminal and quickly launch connections in new tabs/windows.
e.g.
ssh-hosts --terminal_tab_mode --loop
Licensing
Licensed under the MIT license, see also LICENSE.txt
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ssh-hosts-0.4.0.tar.gz
.
File metadata
- Download URL: ssh-hosts-0.4.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5b51bf5b2c51727de32ee7d4e877ad39658eb53ebcdb18f336f583944a5ae91 |
|
MD5 | 85f9cbaecc0d7c897662cb80d3a09e3b |
|
BLAKE2b-256 | 1fd181c83e2d41d48e0ae1ce7b02f70cad104968990151403229c34499c1dec1 |
File details
Details for the file ssh_hosts-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: ssh_hosts-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2a21701031de31e8c30ea393a22732f512aa210675a9367e62ea49ef9ef149 |
|
MD5 | f0c67790170b51a81b8def73d22f06f1 |
|
BLAKE2b-256 | 81e6ce7ed8f7f5fd08d79c36334758ee67f3b19067160fe179858fae88928308 |