[root@node110 paramiko]# cat simple2.py
#!/usr/bin/env python
import paramiko
import os
hostname='192.168.2.120'
username='root'
paramiko.util.log_to_file('syslogin.log')
ssh=paramiko.SSHClient()
ssh.load_system_host_keys()
#privatekey = os.path.expanduser('/home/key/id_rsa')
privatekey = os.path.expanduser('/root/.ssh/id_rsa')
key = paramiko.RSAKey.from_private_key_file(privatekey)
ssh.connect(hostname=hostname,username=username,pkey = key)
stdin,stdout,stderr=ssh.exec_command('free -m')
print stdout.read()
ssh.close()
结果:
[root@node110 paramiko]# python simple2.py
total used free shared buffers cached
Mem: 486 183 303 4 18 57
-/+ buffers/cache: 107 378
Swap: 2015 0 2015
2017-04-10
通过密钥方式登录远程主机
评论
发表评论
姓 名: