ocsh - SSH password log-in and command automator
ocsh automates SSH password login and command execution through annotations on ssh_config(5) Hosts:
- password authentication, reading password from pass[1]:
- config:
# ocsh pass <pass-name> - command:
$ ocsh host
- config:
- post-login command execution:
- config:
# ocsh post <action> "<cmd>" - command:
$ ocsh host[action]
- config:
- post-login command execution, reading additional password from pass[1]:
- config:
# ocsh postpass <action> "<cmd>" <pass-name> - command:
$ ocsh host[action]
- config:
- use different ssh command or prefix by other command:
- config:
# ocsh cmd "<ssh-command>" - config:
# ocsh pre "<pre-command>" - command:
$ ocsh host
- config:
- multiple hosts support for command execution:
- command:
$ ocsh sshaliasprefix*
- command:
[1] https://www.passwordstore.org/
Compatibility with OpenSSH is kept as much as possible:
- support usual SSH aliases, keys and command-line options
- compatible with rsync, scp and other tools using SSH for transport, see example commands
- autocompletion can be set-up with --ocsh-install-autocompletion
Usage
usage: ocsh.py [-h] [--ocsh-verbose] [--ocsh-pretend] [--ocsh-examples]
[--ocsh-install-autocompletion]
[destination] ...
ocsh - SSH password log-in and command automator
positional arguments:
destination host[action] or regex for multiple hosts
args any OpenSSH options or remote command
options:
-h, --help show this help message and exit
--ocsh-verbose enable debug messages
--ocsh-pretend do not actually perform the connection
--ocsh-examples show example ocsh configuration and commands
--ocsh-install-autocompletion
install bash autocompletion for the current user
Installation
pip install ocsh
Examples of usage
# connect to SSH alias 'host1' with automated password login
# ssh_config(5)
Host host1
Hostname 10.0.0.1
User minou
# ocsh pass pass-location # location in password-store
# command
ocsh host1
# equivalent ssh command
sshpass -p "$(pass pass-location)" ssh host1
# connect to SSH alias 'host2' with automated password login, going through the above 'host1', and become root
# ssh_config(5)
Host host2
Host 10.9.0.1
User root
# ocsh pass pass-location2 # location in password-store
# ocsh postpass su "su -l" pass-location3
# ocsh post nsep "ip netns exec nsep" # post-login command to enter a network namespace
# command
ocsh host2[root]
# equivalent ssh command
sshpass -p "$(pass pass-location2)" ssh -oProxyCommand="sshpass -p "$(pass pass-location1)" ssh host1" host2 su -l
<now enter root password (from pass-location3) manually>
# run ssh connection from a different namespace
# ssh_config(5)
Host host1
Hostname 10.0.0.1
User minou
# ocsh pre "ip netns exec toto"
# command
ocsh host1
# equivalent command
ip netns exec ssh host1
# run rsync through ocsh from host1 with automated password login
rsync -e "ocsh" -avP host1:/etc/hosts /tmp/
# run scp through ocsh from host1 with automated password login
scp -S "ocsh" host1:/etc/hosts /tmp/
See also
- netmiko - python library to SSH to various network devices https://github.com/ktbyers/netmiko
- sshpass - automate SSH password-based log-in https://github.com/kevinburke/sshpass
- passh - sshpass alternative to automate SSH password-based log-in https://github.com/clarkwang/passh
Metadata
Release files for ocsh 20230922
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ocsh-20230922.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ocsh-20230922-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.2 kB
Release files / ocsh-20230922.tar.gz
| Download URL | ocsh-20230922.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3eff86b7244e3cd53e2587b96deba09687f51d6b2cd0dfcf9de0e9c041f687b5
|
|
BLAKE2b-256 checksum How to use checksums |
f4fb6ac2bc6c729281bcc8fd9bb1ee2a8454e619ac330a0ea1d0c718c6b1a4f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / ocsh-20230922-py3-none-any.whl
| Download URL | ocsh-20230922-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f24060ada30837dceef3b4443847cd9defbeaaeff603a2e2d259f091729940a4
|
|
BLAKE2b-256 checksum How to use checksums |
9f7ce34f46d74a239b16da12eb33a77d79f36370fae0a8799dfe3753a00ca2a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|