Initial commit
This commit is contained in:
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
|
||||
# Project specific
|
||||
config.yaml
|
||||
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Sync SSH Keys
|
||||
|
||||
## Setup
|
||||
Rename `config-example.yaml` to `config.yaml` and set your own data.
|
||||
|
||||
## Usage
|
||||
Run `./sync.py` or `python3 sync.py`
|
||||
10
config-example.yaml
Normal file
10
config-example.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
hosts:
|
||||
- google.com
|
||||
- amazon.com
|
||||
keys:
|
||||
- name: johndoe@gmail.com
|
||||
description: John Doe
|
||||
key: ssh-rsa XXXXXXXXX
|
||||
- name: janedoe@gmail.com
|
||||
description: Jane Doe
|
||||
key: ssh-rsa YYYYYYYYY
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
PyYAML==5.4.1
|
||||
paramiko==2.7.2
|
||||
46
sync.py
Executable file
46
sync.py
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import paramiko
|
||||
import threading
|
||||
import yaml
|
||||
|
||||
class taskThread(threading.Thread):
|
||||
def __init__(self, host, keys):
|
||||
threading.Thread.__init__(self)
|
||||
self.host = host
|
||||
self.keys = keys
|
||||
def run(self):
|
||||
updateKeys(self.host, self.keys)
|
||||
|
||||
def readConfig():
|
||||
with open('config.yaml', 'r') as stream:
|
||||
return yaml.safe_load(stream)
|
||||
|
||||
def updateKeys(host, keys):
|
||||
try:
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
||||
client.connect(host, username = 'root')
|
||||
client.exec_command('echo "###\n# Warning this file has been generated and will be overwritten!\n###\n\n' + '\n'.join(keys) + '" > ~/.ssh/authorized_keys2')
|
||||
client.close()
|
||||
print('✅ ' + host)
|
||||
except Exception:
|
||||
print('❌ ' + host)
|
||||
|
||||
def main():
|
||||
config = readConfig()
|
||||
|
||||
keys = []
|
||||
|
||||
for key in config['keys']:
|
||||
keys.append(key['key'])
|
||||
|
||||
for host in config['hosts']:
|
||||
try:
|
||||
thread = taskThread(host, keys)
|
||||
thread.start()
|
||||
except:
|
||||
print('❌ ' + host)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user