“ping” isn't allowed to be executed

霸气de小男生 提交于 2019-12-21 19:45:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!