def set_ssh_key(self, check_ssh): # Where our RSA key chould exist self.key_file = (os.path.expanduser('~') + '/.ssh/id_rsa.pub') key_file = (os.path.expanduser('~') + '/.ssh/id_rsa.pub') # If the RSA key doesn't exist, create it if check_ssh == True: if os.path.isfile(key_file) != True: os.system("ssh-keygen -b 2048 -t rsa -f " + key_file + " -q -N ") # Set the member value ssh_key to the value of this file ssh_file = open(key_file) self.ssh_key = ssh_file.read().strip() ssh_file.close() if check_ssh == True: # Upload the SSH key to digital ocean if it isn't there already key_installed = False manager = digitalocean.Manager(token=self.token) keys = manager.get_all_sshkeys() for key in keys: if key.public_key == self.ssh_key: key_installed = True if key_installed == False: key = SSHKey(token=digitalocean_token, name='ocean_key_' + str(random.randint(11111, 99999)), public_key=self.ssh_key) key.create()
def add_pub_key(path, name): with open(path) as f: user_ssh_key = f.read() key = SSHKey(token=TOKEN, name=name, public_key=user_ssh_key) key.create() print(f'[+] added ssh-key: {name}')
def upload_ssh_key(file_pub_name, hostname): user_ssh_key = open(file_pub_name).read() key = SSHKey(token=Configuration['DO_TOKEN'], name=hostname, public_key=user_ssh_key) key.create() print 'Uploaded Keypair' return key.id
def dropletSSHKey(): user_ssh_key = open(f'/home/{USER}/.ssh/id_rsa.pub').read() key = SSHKey(token=API_SECRET, name='archyDesktop', public_key=user_ssh_key) key.create() print("Key Created") input("Press [Enter] to return to the main screen") main()
def create_ssh_key(ssh_key: SSHKey) -> SSHKey: """ API call to DigitalOcean's API v2 in order to create the ssh key. :param digitalocean.SSHKey.SSHKey ssh_key: object :return: digitalocean.SSHKey.SSHKey """ with pong(text=cyan_text("The SSH key is posted...")): ssh_key.create() return ssh_key
def createKey(): user_ssh_key = open(conf.digital_ocean['ssh-key']).read() key = SSHKey(token=conf.digital_ocean['token'], name="template-ssh-key", public_key=user_ssh_key) try: key.create() except Exception as e: print("[!] Already Created: " + str(e)) return print('[+] Key Added to DigitalOcean Account')
def do_ssh_key(self): all_key = self.manager.get_all_sshkeys() for key in all_key: if key.name == SSH_KEY_NAME: return key key = SSHKey( token=self.token, name=SSH_KEY_NAME, public_key=self.config['ssh']['public'], ) key.create() return key
def createKey(): user_ssh_key = open(conf.digital_ocean['ssh-key']).read( ) #get public key to upload to digital ocean key = SSHKey(token=conf.digital_ocean['token'], name="jumper-ssh-key", public_key=user_ssh_key) try: key.create() #If key is already created, an error will throw. except Exception as e: print("[!] Already Created: " + str(e)) return #break on thrown Exception print('[+] Key Added to DigitalOcean Account')