feat: add administrative and deployment scripts for infrastructure management
This commit is contained in:
35
scripts/authorize_and_test.py
Normal file
35
scripts/authorize_and_test.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import paramiko
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
||||
pub_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC6ycMke4AaV2qzWfULZCTZOKhSKf4pY2qRGYjYzs1MGKutJxt2jkYNK2aS0XffxLRR49v23zHbBwLYraNl2Mkb9rsKsyvKn8CAa1CEl9NxOci4LDRT8CeWHRnMZn8Mdu1pfeRwM26/Bjnd4RJrSKC7fyM0OlOpEp0DgnuPBqBtPMFGw+TCUT8eZ0pBrAI94wEan4l35kmuBcqm6RH3KuD1dDJKnPLzJ3/T21CViYL0GgFIDDor/hGI45VfOI/jKmkgM4YoudTCde6uPV5e2yaJpORZlR4nDxg9ntXp8HxbHGZkXYr55Ibsjem0lMU6nBh33jGbJVvat1Ay4oNCbygJsHfC/8ppe0bnLhnasxVAXhTvklZZL/sf7K/VS0ZifpfqB6DKtr1lziOm2wQeahv+Y1uoHkVNa3XY8Fx7xGPeT1BGd9lfcbUoweoTdMPMIPaSZlNGY32AHYkM4PShG9yI1coAqXzMby0+Z/Qwtr4l6cLKVvcGgqh5sd+z1+YvZbs= root@SNINFR2LNXCTL01"
|
||||
|
||||
# 1. Authorize on 140.44.4.71
|
||||
c71 = paramiko.SSHClient()
|
||||
c71.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c71.connect("140.44.4.71", username="root", key_filename=key_path, timeout=10)
|
||||
|
||||
cmd = f"""
|
||||
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
||||
grep -qF '{pub_key}' ~/.ssh/authorized_keys 2>/dev/null || echo '{pub_key}' >> ~/.ssh/authorized_keys
|
||||
chmod 600 ~/.ssh/authorized_keys
|
||||
"""
|
||||
c71.exec_command(cmd)
|
||||
c71.close()
|
||||
print("Authorized 140.44.4.11 key on 140.44.4.71.")
|
||||
|
||||
# 2. Test SSH from 140.44.4.11 to 140.44.4.71
|
||||
c11 = paramiko.SSHClient()
|
||||
c11.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c11.connect("140.44.4.11", username="root", key_filename=key_path, timeout=10)
|
||||
|
||||
stdin, stdout, stderr = c11.exec_command("ssh -o BatchMode=yes -o StrictHostKeyChecking=no root@140.44.4.71 hostname")
|
||||
out = stdout.read().decode('utf-8').strip()
|
||||
err = stderr.read().decode('utf-8').strip()
|
||||
print("Result of ssh from 140.44.4.11 to 140.44.4.71:")
|
||||
print("STDOUT:", out)
|
||||
if err: print("STDERR:", err)
|
||||
c11.close()
|
||||
|
||||
Reference in New Issue
Block a user