ParallelSSH / parallel-ssh

Asynchronous parallel SSH client library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
1.2k stars 149 forks source link

SSH Multiplexing #347

Closed chikkujimmy closed 2 years ago

chikkujimmy commented 2 years ago

I tried using SSH multiplexing (to speed up remote login procedure) by creating a config file in the path ~/.ssh/config with the below content

Host anyhostname (you can give any hostname)
HostName (Host IP address)
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p.socket
ControlPersist 30m

and when I try to call this in the parallel SSH script

from pssh.clients import ParallelSSHClient

host = ['anyhostname']
cmd = 'uptime'
client = ParallelSSHClient(host, user='root', password='password')
#client = ParallelSSHClient(host, user='root')
#client = ParallelSSHClient(host, pkey='~/.ssh/config')
output = client.run_command(cmd)
for host_out in output:
    for line in host_out.stdout:
        print(line)

it is giving an error pssh.exceptions.UnknownHostError: ('Unknown host %s - %s - retry %s/%s', 'anyhostname', 'Temporary failure in name resolution', 3, 3).

But when I try the command line I am able to connect via Parallel SSH

$ parallel-ssh -i -l user1 -o StrictHostKeyChecking=no -h ~/pssh-hosts uptime [1] 16:19:49 [SUCCESS] local-250 16:19:49 up 13:55, 2 users, load average: 23.52, 35.55, 51.63

How can I specify the multiplexing hostnames or implement multiplexing in your parellel SSH script? As per your documentation there are options for password and private key accesses which are working fine

pkittenis commented 2 years ago

Hi there,

Thanks for the interest.

The quickstart documentation describes how to use ParallelSSHClient. This project does not read ~/.ssh/config, nor does it support an SSH config as argument to pkey.

from pssh.clients import ParallelSSHClient

hosts = ['localhost', 'localhost', 'localhost', 'localhost']
client = ParallelSSHClient(hosts)
cmd = 'uname'

output = client.run_command(cmd)
for host_out in output:
    for line in host_out.stdout:
        print(line)

Multiplexing is not supported nor needed for this library. Simply keep the client object in scope to reuse the same connection.