pramiko连接

#生成秘钥

[root@web1 day6]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):

回车输入两次密码

123456

The key fingerprint is:
84:50:56:9b:da:11:26:1b:5b:03:44:a9:4b:2f:f8:52 root@web1.james.top
The key's randomart image is:
+--[ RSA 2048]----+
| .+O+* |
| o.O = |
| .+ = |
| o + . |
| o o. S |
| . E . |
| o . |
| . . |
| . |

 

cat /root/.ssh/id_rsa.pub >/root/.ssh/authorized_keys

chmod 600 !$

由于我这里是测试本机,所以ssh localhost 会提示输入秘钥的密码

之后可以通过pramiko连接远程主机

key = paramiko.RSAKey.from_private_key_file( pkey_file, password='123456' )

try:
     ssh.connect( hostname=host, username=user, pkey=key, timeout=5 )
except:
     print 'connection has some problems...'
     return 1

 

生成ip地址

for i in {1..100}; do ifconfig br0:$i 192.168.20.$i; done

time python 19dsh.py date

[root@web1 day6]# ps -e |grep ssh

1003 ? 00:00:00 sshd
11319 ? 00:00:01 sshd
20932 ? 00:00:00 sshd
20934 ? 00:00:00 sshd
20941 ? 00:00:00 sshd
20942 ? 00:00:00 sshd
20944 ? 00:00:00 sshd
20962 ? 00:00:00 sshd
20978 ? 00:00:00 sshd
20982 ? 00:00:00 sshd
20995 ? 00:00:00 sshd
20998 ? 00:00:00 sshd
21000 ? 00:00:00 sshd
21003 ? 00:00:00 sshd

启动了十个进程

1. 进程池关闭的条件是进程池里的所有进程结束了,才关闭,意味着关闭的时候,进程池里是没有worker进程的。
join()是阻塞主进程,要放在close的后面。
2. 主进程就是python脚本这个进程。

 

posted on 2018-01-15 22:27  linux-paul  阅读(153)  评论(0编辑  收藏  举报

导航