当我尝试使用 Paramiko 执行我得到的任何命令时
"[COMMAND]" isn't allowed to be executed.
但是如果我通过使用 Putty 来做到这一点,它工作正常,知道是什么原因造成的吗?
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'
腻子:
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
最佳答案
Paramiko 的 exec_command(cmd)
将调用 /the/login/shell -c cmd
来运行类似于 ssh user@host cmd
。如果远程服务器上的登录 shell 不支持 -c
,则 exec_command()
将失败。因此,在使用 exec_command()
之前,我通常先从命令行尝试 ssh user@host cmd
。
invoke_shell()
会起作用,因为它会启动一个交互式 session ,就像您使用 PuTTY
手动连接到服务器一样。
关于python - "ping"不允许执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41570124/