Reputation: 612
I'm using Python to SSH into a host, run bash commands, and then parse results in a Pythonic way into several data structures for later display.
I'm using the Paramiko library for SSH and executing commands on the remote host like so:
ssh = paramiko.SSHClient()
ssh.exec_command("command goes here")
I'm running many commands this way and it seems most of them are working (I'm looping through a file and constructing file paths on the remote server to run the commands on). However, about halfway through execution I'm hitting this error.
I think it has something to do with the volume of ssh.exec_command()
calls I'm making but I'm not sure. Any ideas?
Upvotes: 5
Views: 14581
Reputation: 81
I have similar problem, and I found there is a SSH server configuration need be modified, too.
Anyone have similar problem can find "#MaxSessions=10"
in sshd configuration first(In my case, that is /etc/sshd/sshd_config
).
Modify MaxSessions=10
to other values may can solve the problem.
Upvotes: 8
Reputation: 612
I believe I've solved it: because exec_command()
is non-blocking I was essentially trying to run a ton of commands all at once on the remote machine. This was against policy and was blocked.
I worked around this by forcing my script to wait until each command was executed via stdout.readlines()
. It's working great now.
Upvotes: 10