I searched the net for a while to solve my problem and no luck.
My problem is that I cannot get sudo commands to work with paramiko.
At first I tried to just use the SS_Client () function. exec_command (command) to execute the sudo command, but these errors:
sudo: sorry, you must have a tty to run sudo
Then, following the tips of this post: How to make a sudo command using Paramiko , I tried this:
#self._ssh is the SSHClient object
self._ssh.invoke_shell().exec_command(command)
However, most of the time it just gives me:
File "pipelines/load_instance/ssh_tools.py", line 71, in executeCommand
stdin, stdout, stderr = self._ssh.invoke_shell().exec_command(command)
File "<absolute_path>/paramiko/channel.py", line 213, in exec_command
self._wait_for_event()
File "<absolute_path>/paramiko/channel.py", line 1084, in _wait_for_event
raise e
paramiko.SSHException: Channel closed.
Another, I have to say, 40% of the time, I get this:
File "<absolute_path>/paramiko/client.py", line 291, in connect
sock.connect(addr)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
As a side note, I'm trying to run these sudo commands on an instance of Amazon Web Services EC2, so I'm confused about why I got Connection Refused error, because every time I run this code, it is a new new instance ...
In addition, I am using paramiko 1.7.6.