import paramiko, time ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10) pub_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOsRiwuL7nfm1Ruew+Xk+3tbzD9ONyKAO0q2QwkppEPZ snarfnet-automation-master@snarfnet.net" pod_manifest = f""" apiVersion: v1 kind: Pod metadata: name: fix-ssh-21 namespace: kube-system spec: nodeName: sninfr2lnxwrk01 restartPolicy: Never containers: - name: fixer image: busybox imagePullPolicy: IfNotPresent command: ["sh", "-c"] args: - | mkdir -p /host/root/.ssh chmod 700 /host/root/.ssh echo "{pub_key}" > /host/root/.ssh/authorized_keys chmod 600 /host/root/.ssh/authorized_keys mkdir -p /host/etc/dropbear echo "{pub_key}" > /host/etc/dropbear/authorized_keys chmod 600 /host/etc/dropbear/authorized_keys echo "KEYS WRITTEN SUCCESSFULLY" ls -la /host/root/.ssh cat /host/root/.ssh/authorized_keys securityContext: privileged: true volumeMounts: - name: host-root mountPath: /host volumes: - name: host-root hostPath: path: / """ stdin, stdout, stderr = ssh.exec_command('kubectl delete pod fix-ssh-21 -n kube-system --now 2>/dev/null; cat << \'EOF\' | kubectl apply -f -\n' + pod_manifest + '\nEOF') print("APPLY:\n", stdout.read().decode()) time.sleep(5) stdin, stdout, stderr = ssh.exec_command('kubectl logs fix-ssh-21 -n kube-system') print("LOGS:\n", stdout.read().decode()) stdin, stdout, stderr = ssh.exec_command('kubectl delete pod fix-ssh-21 -n kube-system --now') print("CLEANUP:\n", stdout.read().decode()) ssh.close()