def key(): """Shows public key used for SSH authorization with nodes.""" from tensorhive.config import SSH from tensorhive.core.ssh import init_ssh_key from pathlib import Path import os import platform key_path = Path(SSH.KEY_FILE).expanduser() private_key = init_ssh_key(key_path) public_key = private_key.get_base64() info_msg = ''' This is the public key which will be used by TensorHive to reach your configured nodes via SSH, and allow for running remote tasks. Make sure that all nodes you've defined in ~/.config/TensorHive/hosts_config.ini know that key: just copy and paste it into ~/.ssh/authorized_keys on each target node. ''' authorized_keys_entry = 'ssh-rsa {pub_key} {username}@{hostname}'.format( pub_key=public_key, username=os.environ['USER'], hostname=platform.node()) click.echo(info_msg) click.echo(authorized_keys_entry)
def __init__(self): super().__init__() self.infrastructure_manager = InfrastructureManager(SSH.AVAILABLE_NODES) self.dedicated_ssh_key = ssh.init_ssh_key(PosixPath(SSH.KEY_FILE).expanduser()) if not SSH.AVAILABLE_NODES: log.error('[!] Empty ssh configuration. Please check {}'.format(SSH.HOSTS_CONFIG_FILE)) raise ConfigurationException manager_ssh_key_path = SSH.KEY_FILE if SSH.TEST_ON_STARTUP: manager_ssh_key_path = self.test_ssh() self.connection_manager = SSHConnectionManager(config=SSH.AVAILABLE_NODES, ssh_key_path=manager_ssh_key_path) self.service_manager = None