1 Star 0 Fork 0

HankZhou / rsa_pub_push

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sshrsa2.py 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
HankZhou 提交于 2014-02-18 16:00 . first commit
import paramiko
try:
key = paramiko.RSAKey.from_private_key_file(pk_path)
except Exception, ex:
print "%s"%(ex)
sys.exit(1)
def sshcmd(ip, username, passwd, cmd, pk_path):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,username,passwd,timeout=5)
for m in cmd:
stdin, stdout, stderr = ssh.exec_command(m)
out = stdout.readlines()
for o in out:
print o,
print '%s\t0K\n'%(ip)
ssh.close()
except Exception,ex:
print '%s\tError:%s,%s\n'%(ip,Exception,ex)
pushrsa(ip,username,passwd,pk_path)
def pushrsa(ip,username,passwd,pk_path):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=hostname, username=username, password=passwd)
file_open = open(pk_path + ".pub")
try:
rsapb = file_open.read( )
finally:
file_open.close( )
stdin, stdout, stderr=ssh.exec_command('echo %s > /root/.ssh/authorized_keys'%(rsapb.strip('\n')))
print stdout.readlines()
print stderr.readlines()
ssh.close()
except Exception, ex:
print "%s"%(ex)
if __name__ == '__main__':
hostname = '192.168.181.43'
username = 'root'
password = '111111'
pk_path = '/rdoot/.ssh/id_rsa'
cmd = ['date']
threads = []
print "Begin work"
pushrsa(ip,username,passwd,pk_path)
#for i in xxx:
# t=threading.Thread(target=funciton)
# t.start()
Python
1
https://gitee.com/15804268950/rsa_pub_push.git
git@gitee.com:15804268950/rsa_pub_push.git
15804268950
rsa_pub_push
rsa_pub_push
master

搜索帮助