-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetkey.py
38 lines (32 loc) · 1.1 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 = 'AEUser'
server_list = [
'clnode274.clemson.cloudlab.us',
'clnode279.clemson.cloudlab.us',
'clnode281.clemson.cloudlab.us',
'clnode270.clemson.cloudlab.us',
'clnode271.clemson.cloudlab.us',
'clnode254.clemson.cloudlab.us',
'clnode282.clemson.cloudlab.us',
'clnode253.clemson.cloudlab.us',
'clnode259.clemson.cloudlab.us',
'clnode266.clemson.cloudlab.us',
]
# generate keys
for s in server_list:
cmd = f'ssh -o StrictHostKeyChecking=no {user}@{s} "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)