问题
When I try to use Paramiko to exec any command I get
"[COMMAND]" isn't allowed to be executed.
But If I do that by using Putty it works fine, any idea what can be causing this?
Paramiko:
>>>ssh.connect('server',port=22,username='user',password='pass'
>>>stdin,stdout,stderr = ssh.exec_command('ping 8.8.8.8 -c 2')
>>>output = stdout.readlines()
>>>print output
[]
>>>error = stderr.readlines()
>>>print error
>>>u'"ping" isn\'t allowed to be executed.\n'
Putty:
user@server:~$ ping 8.8.8.8 -c 2
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=57 time=15.928 ms
64 bytes from 8.8.8.8: seq=1 ttl=57 time=15.661 ms
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 15.661/15.794/15.928 ms
回答1:
Paramiko's exec_command(cmd)
will invoke /the/login/shell -c cmd
to run the command which is similar to ssh user@host cmd
. If your login shell on the remote server does not support -c
then exec_command()
would fail. So before using exec_command()
I usually first try ssh user@host cmd
from the command line.
invoke_shell()
would work because it starts an interactive session just like you connect to the server manually with PuTTY
.
来源:https://stackoverflow.com/questions/41570124/ping-isnt-allowed-to-be-executed