-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetKey.py
38 lines (32 loc) · 1.11 KB
/
setKey.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
user = 'xuchuan'
server_list = [
'clnode279.clemson.cloudlab.us',
'clnode281.clemson.cloudlab.us',
'clnode264.clemson.cloudlab.us',
'clnode259.clemson.cloudlab.us',
'clnode267.clemson.cloudlab.us',
'clnode271.clemson.cloudlab.us',
'clnode278.clemson.cloudlab.us',
'clnode270.clemson.cloudlab.us',
'clnode282.clemson.cloudlab.us',
'clnode274.clemson.cloudlab.us',
]
# generate keys
for s in server_list:
cmd = f'ssh {user}@{s} -o StrictHostKeyChecking=no "ssh-keygen -t rsa -b 2048 -N \'\' -f ~/.ssh/id_rsa"'
os.system(cmd)
pub_key_list = []
for s in server_list:
cmd = f'scp -o StrictHostKeyChecking=no {user}@{s}:.ssh/id_rsa.pub ./'
os.system(cmd)
with open('id_rsa.pub', 'r') as f:
pub_key_list.append(f.readline())
cmd = f'scp -o StrictHostKeyChecking=no {user}@{server_list[0]}:.ssh/authorized_keys ./'
os.system(cmd)
with open('authorized_keys', 'a') as f:
for key in pub_key_list:
f.write(key)
for s in server_list:
cmd = f'scp -o StrictHostKeyChecking=no ./authorized_keys {user}@{s}:.ssh/authorized_keys'
os.system(cmd)