I’m trying to automate ssh connection. In this session i want to send some commands to log on into another subproces.
import paramiko
import os
import time
ip = 'a'
port = 22
username = 'b'
password = 'c'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
channel = ssh.invoke_shell()
out = channel.recv(9999)
channel.send('net-client\n')
channel.send('connect\n')
channel.send('yes\n')
channel.send('password\n')
channel.send('help\n')
while not channel.recv_ready():
time.sleep(3)
out = channel.recv(9999)
print(out.decode("ascii"))
Manual preparation:
- $(prompt from ssh connection)]
- $ net-client (when i write this command, it open client installed on machine)
- & connect (I have another prompt because i'm in subprocces, I write 'connect')
- Are you sure you want to continue connecting (yes/no)? yes (write 'yes) Interactive SSH Authentication Type your password:
- Password: 'password' (i write password)
- & (now i'm connected in subproces)
Actual result: I have correct answer after "net-client' but when I write next command (in this case 'connect'), this will be written on ssh-connection not i subproces...
I want to continue send commands in this subproces( so put command like connect, password etc.) but my script can't handle this operation.
This my actual print from script:
$
net-client
"Correct answer to the command"
& connect
yes
password
help