“平"不允许被执行 [英] "ping" isn't allowed to be executed

查看:40
本文介绍了“平"不允许被执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 Paramiko 执行任何命令时,我得到 <块引用>

不允许执行[COMMAND]".

但是如果我使用 Putty 来做到这一点,它就可以正常工作,您知道是什么原因造成的吗?

参数:

>>>ssh.connect('server',port=22,username='user',password='pass'>>>stdin,stdout,stderr = ssh.exec_command('ping 8.8.8.8 -c 2')>>>输出 = stdout.readlines()>>>打印输出[]>>>error = stderr.readlines()>>>打印错误>>>u'"ping" 不允许被执行.\n'

腻子:

user@server:~$ ping 8.8.8.8 -c 2PING 8.8.8.8 (8.8.8.8):56 个数据字节来自 8.8.8.8 的 64 个字节:seq=0 ttl=57 time=15.928 ms来自 8.8.8.8 的 64 个字节:seq=1 ttl=57 time=15.661 ms--- 8.8.8.8 ping 统计 ---发送 2 个数据包,接收 2 个数据包,0% 数据包丢失往返最小/平均/最大 = 15.661/15.794/15.928 毫秒

解决方案

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() 会起作用,因为它会启动交互式会话,就像您使用 PuTTY 手动连接到服务器一样.

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

解决方案

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.

这篇关于“平"不允许被执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆