【发布时间】:2019-09-28 01:00:15
【问题描述】:
我正在尝试使用 ssh2 和 Python 从我的笔记本电脑(本地)执行一些命令到我的专用机器。
当我尝试使用 ls 命令显示所有文件时,我总是收到此消息。
> Linux v2 5.2.13-gs-md #5213 SMP Sun Sep 8 01:47:29 CEST 2019 x86_64
>
> The programs included with the Debian GNU/Linux system are free software;
> the exact distribution terms for each program are described in the
> individual files in /usr/share/doc/*/copyright.
>
> Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
> permitted by applicable law.
这是我的代码。
import socket, time
from ssh2.session import Session
host = '11.22.33.44.55'
user = 'root'
password = 'itssecret'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 2244))
session = Session()
session.handshake(sock)
session.userauth_password(user, password)
channel = session.open_session()
channel.shell()
channel.write("cd /")
channel.write("ls")
time.sleep(1)
size, data = channel.read()
print(data.decode())
channel.close()
即使我只尝试cd / 我也有相同的输出。
【问题讨论】:
-
这是每次登录服务器时显示的
/etc/issue文件的内容。 -
我尝试使用
paramiko通过SSH 连接到我的Linux 机器,没有出现这样的问题。 paramiko.org -
如果您对服务器进行交互式 ssh,您难道看不到吗?
-
Paramiko 可能没有进行交互式登录,
ssh2.session是。 -
所以实际上我已经登录了,但我什么也做不了?