用python实现SSH的免密码输入访问客户端

1. pexpect - http://pexpect.sourceforge.net/pexpect.html

代码举例:

import pexpect

child = pexpect.spawn('ssh [email protected] ls /home')
child.expect('Password:')
child.sendline('mima')




2. paramiko - http://www.lag.net/paramiko/

代码举例:

import paramiko

client = paramiko.SSHClient()
client.load_system_host_keys()
ip = '192.168.100.6'
client.connect(ip, username='root', password='mima')
i, o, e = client.exec_command('apt-get install sl -y --force-yes')
print o.read(), e.read()
client.close()

你可能感兴趣的:(html,.net,python,ssh)