Metadata-Version: 2.1
Name: sshx
Version: 0.19.8
Summary: SSH eXtensions
Home-page: https://github.com/WqyJh/sshx
Author: wqy
Author-email: qiyingwangwqy@gmail.com
License: GNU General Public License v3
Keywords: ssh,paramiko
Platform: UNKNOWN
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Description-Content-Type: text/markdown
Requires-Dist: itsdangerous
Requires-Dist: pexpect
Requires-Dist: paramiko

# sshx (SSH eXtensions)

[![Build Status](https://travis-ci.org/WqyJh/sshx.svg?branch=master)](https://travis-ci.org/WqyJh/sshx)
[![codecov](https://codecov.io/gh/WqyJh/sshx/branch/master/graph/badge.svg)](https://codecov.io/gh/WqyJh/sshx)
[![license](https://img.shields.io/badge/LICENCE-GPLv3-brightgreen.svg)](https://raw.githubusercontent.com/WqyJh/sshx/master/LICENSE)


sshx is a lightweight wrapper for ssh/scp command, which has the following features:
- Remember your ssh account
- Connect to your account with a short command, without typing password
- Enable jump host for your connection
- Create ssh forwarding with a short command, without typing password
- Enable jump host for your port forwarding
- Copy files from/to your account with a short command, without typing password
- Enable jump host for your scp connection


## Installation

### Install from pypi

For **Windows**:

```bash
pip install --extra-index-url https://wqyjh.github.io/python-wheels/ sshx
```

For **Linux**, **macOS**:

```bash
pip install sshx
```

### Install from source

For **Windows**:
```bash
pip install --extra-index-url https://wqyjh.github.io/python-wheels/ git+https://github.com/WqyJh/sshx

# Or

pip install -i  https://wqyjh.github.io/python-wheels/ pyHook
python setup.py install

# Or

pip install -r requirements.txt
```

For **Linux**, **macOX**:
```bash
pip install git+https://github.com/WqyJh/sshx

# Or

python setup.py install

# Or

pip install -r requirements.txt
```


## Quick Start

1. Initialization.

```bash
sshx init
```

2. Adding an account.

```bash
sshx add myhost -l test@192.168.9.155
```

(This command will ask you to type your password and sshx would store the encrypted password.)

3. Connect to the account.

```bash
sshx connect myhost
```

## Usage

### Initialization

`sshx init` performs initialization.

It will automatically create the following files which storing the account info. If the files are damaged you'll probably 
lost all the account records, so **DON'T TOUCH IT**. If this happened, use this command to re-init and use
`add` command to re-add them.

```bash
$ sshx init
$ tree ~/.sshx
~/.sshx
└── .accounts
```

### Add accounts

`sshx add` adds an account.

```bash
# add an account in an simple way
sshx add myhost -l user@host:port

# add an account and specify an password for authentication
sshx add myhost -H host -P port -u user -p

# add an account and specify an identity file for authentication
sshx add myhost -H host -P port -u user -i identity_file

# add an account and specify both password and identity file for authentication
sshx add myhost -H host -P port -u user -p -i identity_file

# add an account named myhost2 and specify an password for authentication
# use pre-added myhost as it's jump host
sshx add -l user@host:port -v myhost myhost2
```

- Host and user options are required for adding an account.
- Either a password or a identity option is required for adding an account. You can also specify both of them for an account. In this case, only using identity for authentication(maybe improved later).
- Password are input from the prompt, which won't show in the screen.


### Show accounts


`sshx list` lists all the accounts in the following format.

```bash
name                host                          user                via                 
-----               -----                         -----               -----               
host1               192.168.7.1                   root                                    
host2               192.168.7.2                   test                host1               
host3               192.168.7.3                   root                host2               
```

`sshx show` show details for a specified account.

```bash
sshx show host1     # Show account info
sshx show host2 -p  # Show account info with password
```

### Delete accounts

`sshx del` deletes an account.

```bash
sshx del host1
```

### Update accounts

`sshx update` updates an account.

The supported options are the same with `add` command, all the specified fields will be updated.

```bash
# change the host1's host field to domain.com
sshx update host1 -H domain.com

# change the host1's password
sshx update host1 -p

# change the host1's identity to identity2
sshx update host1 -i identity2

# TODO
# change the host1's name to host2, and the next time you want to 
# change the account you have to use `sshx update host2 ...`
#sshx update host1 -n host2
```

### Connect accounts

`sshx connect` connect to an account.

```bash
# Connect to host1 directly.
sshx connect host1

# Connect to host1 using host2 as jump host.
# If the host1 was originally has an jump host,
# this argument would temporarily override it.
sshx connect host1 -v host2

# Connect to hsot1 using host2 as jump host,
# while the host2 is using host3 as jump host.
sshx connect host1 -v host2,host3
```

**Note** that if you use `-v` option, all of the accounts' 
via field will be ignored.


### Create socks5 proxies

`sshx socks` creates socks5 proxies.

```bash
sshx socks host1 # create socks proxy on port 1080
sshx socks host1 -p 1080 # create socks proxy on port 1081
```

Why create socks5 proxies with ssh?

Because it's very simple and safe.
- `simple` no configurations and installations, all you need is just an ssh server
- `safe` all traffic will be encrypted by ssh, safer than `shadowsocks`


### Create port forwardings

`sshx forward` creates port fowardings.

```bash
sshx forward host1 [-f <map1> [map2]] [-rf <rmap1> [rmap2]] [-v host2[,host3]]

map: [bind_address]:bind_port:remote_address:remote_port

rmap: bind_address:bind_port:local_address:local_port
```

For example:

```bash
# Forward localhost:8888 to 192.168.77.7:80, 
# while the host1 is the intermedia server, 
# so you must ensure the host1 could dial to 192.168.77.7:80.
sshx forward host1 -f :8888:192.168.77.7:80
```

```bash
# Forward host1:8888 to 192.168.99.9:8888. 
# When you access localhost:8000 on host1, 
# the connection would be forward to 192.168.99.9:8888, 
# while your computer is working as a intermediate server 
# so you have to ensure your computer has access to 192.168.99.9:8888.
sshx forward host1 -r :8000:192.168.99.9:8888
```

- You can use `-f` and `-rf` arguments simultaneously.
- You can also specify multiple maps after either `-f` or `-rf`.
- You can use `-v` option to specify jump hosts just as connect.


### Copy files

`sshx scp` copy files to/from servers.

```bash
# Copy local files to host1
sshx scp <src> host1:<dst>

# Copy remote files from host1 to local
sshx scp host1:<src> <dst>

# Copy local files to host1, using host2 as jump host
sshx scp <src> host1:<dst> -v host2

# Copy remote files to local, using host2 as jump host
# and using host3 as host2's jump host.
sshx scp host1:<src> <dst> -v host2,host3
```

TODO:
```bash
# Copy remote files from host1 to host2
sshx scp host1:<src> host2:<dst>
```


### Execute command

`sshx exec` execute an remote command.

```bash
# Execute `ls -al` on host1
sshx exec host1 ls -al
# Execute an command with tty
sshx exec host1 /bin/bash
# Execute an command on host1 via host2
sshx exec -v host2 host1 ls -al
```


## Test

```bash
python setup.py test
```

## Todo

- [x] scp support
- [x] jump host support


## Bugs


### Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [0.19.8](https://github.com/WqyJh/sshx/compare/0.17.5...0.19.8)

> 8 October 2019

- fix(update): fix rename account [`#43`](https://github.com/WqyJh/sshx/pull/43)
- feat: add sort and reverse for command list [`#42`](https://github.com/WqyJh/sshx/pull/42)
- add comand exec [`#41`](https://github.com/WqyJh/sshx/pull/41)
- refactor: remove win cmd support [`#40`](https://github.com/WqyJh/sshx/pull/40)
- chore: use pipenv to replace pip [`#38`](https://github.com/WqyJh/sshx/pull/38)
- Fix update [`#36`](https://github.com/WqyJh/sshx/pull/36)
- feat: add command exec [`2047646`](https://github.com/WqyJh/sshx/commit/20476467d28742bf28bceca154009c4df1f094a7)
- refactor: remove interact for exec [`b803b06`](https://github.com/WqyJh/sshx/commit/b803b064fbe3a2ac56c11a2c2c745d9ae8d01704)
- docs: update README.md for command exec [`8116229`](https://github.com/WqyJh/sshx/commit/81162298875ab18060e8209b00a245502ca3d32b)

#### [0.17.5](https://github.com/WqyJh/sshx/compare/0.4.3...0.17.5)

> 20 September 2019

- Release 0.17 [`#35`](https://github.com/WqyJh/sshx/pull/35)
- Fix unitest [`#33`](https://github.com/WqyJh/sshx/pull/33)
- Add ssh socks [`#32`](https://github.com/WqyJh/sshx/pull/32)
- feat: add command show [`#31`](https://github.com/WqyJh/sshx/pull/31)
- fix: fix uploading failure on OSX [`#26`](https://github.com/WqyJh/sshx/pull/26)
- refactor: merge the interact and non interact version of ssh_pexpect [`6ac0424`](https://github.com/WqyJh/sshx/commit/6ac042412644745050fd2d85568c60b83a816d4e)
- docs: update CHANGELOG.md [`033a51a`](https://github.com/WqyJh/sshx/commit/033a51ac9585c3aed97a3d8698a9539443f651ea)
- feat: add socks command [`3446e68`](https://github.com/WqyJh/sshx/commit/3446e68bbe4d8849bd0ca6be26426b8066889b67)

#### [0.4.3](https://github.com/WqyJh/sshx/compare/0.3.1...0.4.3)

> 14 July 2019

- Release 0.4.3 [`#24`](https://github.com/WqyJh/sshx/pull/24)
- Remove py2 [`#23`](https://github.com/WqyJh/sshx/pull/23)
- feat: remove python 2 support [`01fe616`](https://github.com/WqyJh/sshx/commit/01fe6160dbe40bd336397297387e2a0b45777b1a)
- chore: add auto-changelog [`ab37b65`](https://github.com/WqyJh/sshx/commit/ab37b654d1fc52db3a631260d8fcfcffc4679a29)
- chore: remote auto-changelog [`17ea081`](https://github.com/WqyJh/sshx/commit/17ea081c8f615c79af04829709f62ba7efae83b5)

#### [0.3.1](https://github.com/WqyJh/sshx/compare/0.3.0...0.3.1)

> 13 July 2019

- Release 0.3.1 [`#22`](https://github.com/WqyJh/sshx/pull/22)
- Fix output with logging module [`#21`](https://github.com/WqyJh/sshx/pull/21)
- feat: add logging [`a8fd721`](https://github.com/WqyJh/sshx/commit/a8fd7210e556e145c9fdee7aac9a2d23f692520d)
- chore: add auto deployment to PYPI [`ddb3044`](https://github.com/WqyJh/sshx/commit/ddb304446121b13a39c09b8767c758ff0001b3d9)
- fix: remove prints [`d7452a1`](https://github.com/WqyJh/sshx/commit/d7452a1a498991b57130fbe5af78e7f957c0e8cf)

#### [0.3.0](https://github.com/WqyJh/sshx/compare/0.2.1...0.3.0)

> 12 July 2019

- Release 0.3 [`#19`](https://github.com/WqyJh/sshx/pull/19)
- Add scp support [`#18`](https://github.com/WqyJh/sshx/pull/18)
- feat: add jump host for scp [`b8ed38f`](https://github.com/WqyJh/sshx/commit/b8ed38fc1a93d1ba3d55695edd9b08ded7c1284c)
- feat: add sshx forward command [`85a344a`](https://github.com/WqyJh/sshx/commit/85a344ab6e081f6f807c4ff28d41d6c8ca3869c2)
- feat: add scp command [`48bd0fd`](https://github.com/WqyJh/sshx/commit/48bd0fd4200a9b9328c2c8b4b9379106a5ee9a40)

#### [0.2.1](https://github.com/WqyJh/sshx/compare/0.2.0...0.2.1)

> 23 June 2019

- Release 0.2.1 [`#17`](https://github.com/WqyJh/sshx/pull/17)
- feat: add via argument for connect [`#16`](https://github.com/WqyJh/sshx/pull/16)
- version: 0.2.1 [`1553d85`](https://github.com/WqyJh/sshx/commit/1553d85353dc9dd68734bb9184b2907f40ded419)

#### [0.2.0](https://github.com/WqyJh/sshx/compare/0.1.0...0.2.0)

> 23 June 2019

- version: 0.2.0 [`#15`](https://github.com/WqyJh/sshx/pull/15)
- Add jump host [`#14`](https://github.com/WqyJh/sshx/pull/14)
- refactor: Encapsulate the config and account into class [`6c6864b`](https://github.com/WqyJh/sshx/commit/6c6864bd296d1060f3d6fd873f2b4439df6900d0)
- refactor: Use Account in sshwrap [`39291f5`](https://github.com/WqyJh/sshx/commit/39291f5add0ffbe0e081989b58ba6914e09d7829)
- feat: add jump connection for pexpect [`ea22b44`](https://github.com/WqyJh/sshx/commit/ea22b4492ee2f3bd9f3892044e248d6f646e6513)

#### 0.1.0

> 18 October 2018

- Add simplifier syntax for add command [`#12`](https://github.com/WqyJh/sshx/pull/12)
- feat: Add auto-adjust window size [`#11`](https://github.com/WqyJh/sshx/pull/11)
- Finished basic function [`9772f83`](https://github.com/WqyJh/sshx/commit/9772f83ea3c9a3eb663fd08370af6b83c005750e)
- Initial commit [`1d97f1d`](https://github.com/WqyJh/sshx/commit/1d97f1d68ab4781c63a5f9fbbecd5417cd50b1ed)
- Add password encrypt [`95e2604`](https://github.com/WqyJh/sshx/commit/95e26049ec0cd22c671b88e8f6e4fd077e18a603)


