1

Trying to SSH from windows server to a Linux remote connection using SSH and paramiko and just 'pwd' this server with the following code (I've changed the user/password and server IP from real code):

import paramiko
from paramiko import SSHClient, AutoAddPolicy
LOCAL_IP=IP
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(LOCAL_IP,username=username, password=password)
client.exec_command('pwd')

I'm getting the following result:

(<paramiko.ChannelFile from <paramiko.Channel 0 (open) window=24576 -> <paramiko.Transport at 0x6716710L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>,
 <paramiko.ChannelFile from <paramiko.Channel 0 (open) window=24576 -> <paramiko.Transport at 0x6716710L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>,
 <paramiko.ChannelFile from <paramiko.Channel 0 (open) window=24576 -> <paramiko.Transport at 0x6716710L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>)

The SSH connection IS open, I can tell by netstat at the linux server that I'm trying to SSH to....

Itaybz
  • 63
  • 1
  • 6

1 Answers1

1

client.exec_command returns a tuple of stdin, stdout and stderr streams - you'll need to assign these and call read() on them to get the output:

import paramiko
from paramiko import SSHClient, AutoAddPolicy
LOCAL_IP=IP
PORT=your_port
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(LOCAL_IP, PORT, username="username", password="password")
stdin, stdout, stderr = client.exec_command("pwd")
print(stdout.read())