Skip to content
Snippets Groups Projects

Generate SSH Key ending with [STRING].

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Christian Dresen
    Usage: python3 generate_ssh.py STRING
    generate_ssh.py 1.46 KiB
    import os
    from multiprocessing import Process, Lock
    import uuid
    
    def work(lock, num, stri):
    	case_insensitive = False
    	comment = stri
    	os.system("mkdir /tmp/ram/{} 2> /dev/null".format(num))
    	key_name = "/tmp/ram/{num}/key_{num}".format(num=num)
    	while True:
    		os.system("rm {}* 2> /dev/null".format(key_name))
    		os.system("ssh-keygen -t ed25519 -f {} -C {} -N '' 2>&1 > /dev/null".format(key_name, comment))
    		k = open("{}.pub".format(key_name),"r").read().split(" ")[1]
    		a = stri.lower() if case_insensitive else stri
    		b = k[-1*len(stri):].lower() if case_insensitive else k[-1*len(stri):]
    		if a == b:
    			os.system("mkdir -p /tmp/keys/{uid}_{last_char};cp {key_name}* /tmp/keys/{uid}_{last_char}/".format(uid=str(uuid.uuid4()),key_name=key_name, last_char=k[-1*len(stri):]));
    			with lock:
    				print("FOUND KEY ENDING WITH {}".format(k[-1*len(stri):]))
    				print("Public Key")
    				print(open("{}.pub".format(key_name),"r").read())
    			break
    
    
    if __name__ == '__main__':
        if len(sys.argv) != 2:
            print("Please provide search string")
        else:
            stri = sys.argv[1]
            threads = 60
            lock = Lock()
            os.system("mkdir /tmp/ram/ 2> /dev/null")
            try:
                os.system("mount -t tmpfs -o size=200M none  /tmp/ram")
                for num in range(threads):
                    Process(target=work, args=(lock,num, stri)).start()
                x=input("Press Enter to Exit\n")
                sys.exit()
            finally:
                os.system("umount /tmp/ram")
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment