我正在使用 openSSH 在测试机(Windows XP)和控制器机(win 7)之间建立 ssh 连接。我已经在测试机器上配置了 ssh 服务器,并且能够获取 ssh 会话并运行命令。当我在这个 ssh 会话中运行命令时,我在 putty 会话中显示了 o/p,但是当我使用相同的命令并尝试检索 o/p 时,我没有得到任何价值。
我已经在我的 XP 机器上安装了 openssh,这是适用于 Windows v3.8.1p1-1 的版本 OpenSSH。
这就是我将其配置为在 Windows 上运行 ssh 的方式
C:\Documents and Settings\Administrator>cd c:\OpenSSH
C:\OpenSSH>cd bin
C:\OpenSSH\bin>mkgroup -l >> ..\etc\group
C:\OpenSSH\bin>mkpasswd -l -u administrator >> ..\etc\passwd
C:\OpenSSH\bin>net start opensshd
The requested service has already been started.
下面是我的相同代码
import paramiko
class TestSSH():
def __init__(self):
self.ip = "172.xxx.xxx.xxx"
self.user = "Administrator"
self.password = "passpass"
def run(self):
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(
self.ip,
username = self.user,
password = self.password
)
std_in, std_out, std_err = ssh_client.exec_command("dir")
print std_out.read()
obj = TestSSH()
obj.run()
这是我在腻子会话中得到的 o/p -
Directory of C:\Documents and Settings\Administrator
11/14/2013 03:11 PM <DIR> .
11/14/2013 03:11 PM <DIR> ..
11/14/2013 03:12 PM <DIR> Desktop
07/27/2011 06:00 PM <DIR> Favorites
11/14/2013 03:11 PM <DIR> hemant
07/27/2011 06:00 PM <DIR> My Documents
07/27/2011 11:12 PM <DIR> Start Menu
0 File(s) 0 bytes
7 Dir(s) 39,932,612,608 bytes free
C:\Documents and Settings\Administrator>
但是我没有得到任何 o/p
我已经尝试过使用 Windows 名称 freeSSHd 的其他 sshutility,我可以通过 putty 连接并执行命令,但是,我只能连接但不能执行命令。freeSSHd 服务器出现以下错误。
Unable to execute command or shell on remote system: Failed to Execute process.
此 o/p 进入 std_out 而不是 std_err 变量。