You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/advanced.rst
+93-21Lines changed: 93 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,23 @@
1
1
.. contents::
2
2
3
3
4
-
***************
5
4
Advanced Usage
6
-
***************
5
+
=================
7
6
8
7
There are several more advanced use cases of `ParallelSSH`, such as tunneling (aka proxying) via an intermediate SSH server and per-host configuration and command substitution among others.
9
8
9
+
Agents and Private Keys
10
+
*************************
11
+
10
12
SSH Agent forwarding
11
-
*********************
13
+
-----------------------
12
14
13
15
SSH agent forwarding, what ``ssh -A`` does on the command line, is supported and enabled by default. Creating an object as ``ParallelSSHClient(hosts, forward_ssh_agent=False)`` will disable this behaviour.
14
16
15
17
Programmatic Private Keys
16
-
**************************
18
+
--------------------------
17
19
18
-
By default, `ParallelSSH` will use all keys in an available SSH agent and all available keys under the user's SSH directory (`~/.ssh`).
20
+
By default, ``ParallelSSH`` will use all keys in an available SSH agent and identity keys under the user's SSH directory - ``id_rsa`` and ``id_dsa`` in ``~/.ssh``.
19
21
20
22
A private key can also be provided programmatically.
21
23
@@ -26,21 +28,32 @@ A private key can also be provided programmatically.
Where `my_key` is a private key file in current working directory.
31
+
Where ``my_key`` is a private key file in current working directory.
32
+
33
+
The helper function :py:func:`load_private_key <pssh.utils.load_private_key>` will attempt to load all available key types and raises :mod:`SSHException <pssh.exceptions.SSHException>` if it cannot load the key file.
30
34
31
-
The helper function :py:func:`pssh.utils.load_private_key` will attempt to load all available key types and raises :mod:`pssh.exceptions.SSHException` if it cannot load the key file.
35
+
Disabling use of system SSH Agent
36
+
----------------------------------
32
37
33
-
Using an available SSH agent can also be disabled programmatically.
38
+
Use of an available SSH agent can also be disabled.
For large number of hosts, it is recommended that private keys are provided programmatically and use of SSH agent is disabled via ``allow_agent=False`` as above.
48
+
49
+
If the number of hosts is large enough, available connections to the system SSH may be exhausted which will stop the client from working on a subset of hosts.
50
+
51
+
This is a limitation of the underlying SSH client used by ``ParallelSSH``.
52
+
40
53
Programmatic SSH Agent
41
-
***********************
54
+
-----------------------
42
55
43
-
It is also possible to programmatically provide an SSH agent for the client to use, instead of a system provided one. This is useful in cases where different hosts in the host list need different private keys and a system SSH agent is not available.
56
+
It is also possible to programmatically provide an SSH agent for the client to use, instead of a system provided one. This is useful in cases where hosts need different private keys and a system SSH agent is not available.
44
57
45
58
.. code-block:: python
46
59
@@ -56,22 +69,26 @@ It is also possible to programmatically provide an SSH agent for the client to u
56
69
client = ParallelSSHClient(hosts, agent=agent)
57
70
client.run_command(<..>)
58
71
59
-
Supplying an agent object programmatically implies that a system SSH agent will *not* be used if available.
72
+
.. note::
73
+
74
+
Supplying an agent programmatically implies that a system SSH agent will *not* be used even if available.
60
75
61
76
62
77
Tunneling
63
78
**********
64
79
65
80
This is used in cases where the client does not have direct access to the target host and has to authenticate via an intermediary, also called a bastion host, commonly used for additional security as only the bastion host needs to have access to the target host.
66
81
67
-
ParallelSSHClient ------> SSH Proxy server --------> SSH target host
Configuration for the proxy host's user name, port, password and private key can also be provided, separete from target host user name.
91
+
Configuration for the proxy host's user name, port, password and private key can also be provided, separate from target host user name.
75
92
76
93
.. code-block:: python
77
94
@@ -83,7 +100,15 @@ Configuration for the proxy host's user name, port, password and private key can
83
100
proxy_port=2222,
84
101
proxy_pkey=load_private_key('proxy.key'))
85
102
86
-
Where `proxy.key` is a filename containing private key to use for proxy host authentication.
103
+
Where ``proxy.key`` is a filename containing private key to use for proxy host authentication.
104
+
105
+
In the above example, connection to the target host is made via ``my_proxy_user@bastion`` -> ``target_host_user@<host>``.
106
+
107
+
.. note::
108
+
109
+
Proxy host connections are asynchronous and use the SSH protocol's native TCP tunneling - aka local port forward. No external commands are used for the proxy connection, unlike the `ProxyCommand` directive in OpenSSH and other utilities.
110
+
111
+
While the connections initiated by ``ParallelSSH`` are asynchronous, the connections from proxy host -> target hosts may not be, depending on SSH server implementation. If only one proxy host is used to connect to a large number of target hosts and proxy SSH server connections are *not* asynchronous, this may adversely impact performance on the proxy host.
87
112
88
113
Per-Host Configuration
89
114
***********************
@@ -109,21 +134,25 @@ Sometimes, different hosts require different configuration like user names and p
109
134
client.run_command('uname')
110
135
<..>
111
136
112
-
In the above example, `host1` will use user name `user1` and private key from `my_key.pem` and `host2` will use user name `user2` and private key from `my_other_key.pem`.
137
+
In the above example, ``host1`` will use user name ``user1`` and private key from ``my_key.pem`` and ``host2`` will use user name ``user2`` and private key from ``my_other_key.pem``.
138
+
139
+
.. note::
140
+
141
+
Proxy host cannot be provided via per-host configuration at this time.
113
142
114
143
Per-Host Command substitution
115
144
******************************
116
145
117
146
For cases where different commands should be run each host, or the same command with different arguments, functionality exists to provide per-host command arguments for substitution.
118
147
119
-
The `host_args` keyword parameter to `run_command` can be used to provide arguments to use to format the command string.
148
+
The ``host_args`` keyword parameter to :py:func:`run_command <pssh.pssh_client.ParallelSSHClient.run_command>` can be used to provide arguments to use to format the command string.
120
149
121
-
Number of `host_args` items should be at least as many as number of hosts.
150
+
Number of ``host_args`` items should be at least as many as number of hosts.
122
151
123
152
Any Python string format specification characters may be used in command string.
124
153
125
154
126
-
In the following example, first host in hosts list will use cmd `host1_cmd` second host `host2_cmd` and so on
155
+
In the following example, first host in hosts list will use cmd ``host1_cmd`` second host ``host2_cmd`` and so on
127
156
128
157
.. code-block:: python
129
158
@@ -140,12 +169,55 @@ Command can also have multiple arguments to be substituted.
140
169
('host2_cmd1', 'host2_cmd2'),
141
170
('host3_cmd1', 'host3_cmd2'),))
142
171
143
-
A list of dictionaries can also be used as `host_args` for named argument substitution.
172
+
A list of dictionaries can also be used as ``host_args`` for named argument substitution.
144
173
145
-
In the following example, first host in host list will use cmd `host-index-0`, second host `host-index-1` and so on.
174
+
In the following example, first host in host list will use cmd ``host-index-0``, second host ``host-index-1`` and so on.
Since generators by design only iterate over a sequence once then stop, ``client.hosts`` should be re-assigned after each call to ``run_command`` when using generators as target of `client.hosts`.
213
+
214
+
Overriding hosts list
215
+
----------------------
216
+
217
+
Hosts list can be modified in place. A call to ``run_command`` will create new connections as necessary and output will only contain output for the hosts ``run_command`` executed on.
Copy file name to clipboardExpand all lines: doc/front_page.rst
+7-10Lines changed: 7 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,16 +16,13 @@ Parallel-SSH Documentation
16
16
:alt:Latest documentation
17
17
18
18
19
-
`Parallel-SSH` is a parallel SSH client library. It makes use of gevent to make asynchronous SSH connections for its client and is, to date, the only publicly available asynchronous SSH client library for Python, as well as the only asynchronous *parallel* SSH client library available for Python.
20
-
21
-
22
-
***********
23
-
User Guide
24
-
***********
19
+
`Parallel-SSH` is a parallel SSH client library. It uses asynchronous SSH connections and is, to date, the only publicly available asynchronous SSH client library for Python, as well as the only asynchronous *parallel* SSH client library available for Python.
0 commit comments