PythonParamiko:已使用SSH连接到服务器,未从“ls”命令获取输出

2024-04-19 03:42:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Paramiko做了一个客户机-服务器程序。我设法获得连接,并发送命令。 例如,如果我发送一个“ifconfig”命令,它确实会返回所需的输出。然而,当我尝试发送“ls”命令时,它什么也不返回。我需要服务器让我使用更复杂的命令,比如打开文件、编辑wordpress等等

这将发送sshCommand:

def sshCommand(command, port=22):
    sshClient = paramiko.SSHClient()  # create SSHClient instance

    sshClient.set_missing_host_key_policy(
        paramiko.AutoAddPolicy())  # AutoAddPolicy automatically adding the hostname and new host key
    sshClient.load_system_host_keys()
    sshClient.connect(host, port, username, password)
    stdin, stdout, stderr = sshClient.exec_command(command)
    print(stdout.read())

当我发送-

sshCommand('ifconfig')

一切正常。 但是,发送-

sshCommand('ls')

可能是因为某种原因我没有访问这些文件的权限吗?我还有用于连接的根密码

任何帮助都将不胜感激


Tags: 文件key命令hostparamikoportstdoutls