This commit is contained in:
@@ -1,21 +1,24 @@
|
||||
#! /usr/bin/env python3.12
|
||||
import subprocess, os
|
||||
#! /usr/bin/env python3.13
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def import_ssh_keys_to_agent(privat_key = str):
|
||||
|
||||
def import_ssh_keys_to_agent(privat_key=str):
|
||||
try:
|
||||
run_add_key = subprocess.run(
|
||||
[ "/usr/bin/ssh-add","-q", privat_key],
|
||||
shell=False,
|
||||
text=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=10,)
|
||||
run_add_key = subprocess.run(
|
||||
["/usr/bin/ssh-add", "-q", privat_key],
|
||||
shell=False,
|
||||
text=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
print("\n","Timeout, No Import :", privat_key)
|
||||
print("\n", "Timeout, No Import :", privat_key)
|
||||
return False
|
||||
|
||||
# print(run_add_key)
|
||||
|
||||
# print(run_add_key)
|
||||
if run_add_key.returncode == 0:
|
||||
return True
|
||||
else:
|
||||
@@ -25,23 +28,23 @@ def import_ssh_keys_to_agent(privat_key = str):
|
||||
def check_key_exist(ssh_pub=str):
|
||||
if not os.path.exists(ssh_pub):
|
||||
return False
|
||||
run_check_key = subprocess.run(
|
||||
[ "/usr/bin/ssh-add","-L"],
|
||||
shell=False,
|
||||
text=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,)
|
||||
run_check_key = subprocess.run(
|
||||
["/usr/bin/ssh-add", "-L"],
|
||||
shell=False,
|
||||
text=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
list_agent_pubs = str(run_check_key.stdout,encoding="utf-8").splitlines()
|
||||
list_agent_pubs = str(run_check_key.stdout, encoding="utf-8").splitlines()
|
||||
read_input_pub = open(ssh_pub)
|
||||
READ_FILE_PUB = read_input_pub.read()
|
||||
count=0
|
||||
READ_FILE_PUB = read_input_pub.read()
|
||||
count = 0
|
||||
for pub in list_agent_pubs:
|
||||
count = count +1
|
||||
count = count + 1
|
||||
if READ_FILE_PUB == pub + "\n":
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user