def setup_efs(cluster): # TODO: check that cluster['sgn'] allows traffic on port 2049 from cluster['efs'] security group # and cluster['efs'] security group allows traffic on port 22 from anywhere mntcmd = ( 'sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ' + cluster['efs'] + ':/ /efs') headclient = pclient.SSHClient() headclient.set_missing_host_key_policy(pclient.AutoAddPolicy()) hip = cluster['head']['public'] kfn = cluster['key'] + '.pem' headclient.connect(hip, username='******', key_filename=kfn) headfclient = headclient.open_sftp() exssh(headclient, 'sudo mkdir -p /efs') exssh(headclient, mntcmd, ignore=[32]) # Push batchtools.conf.R to /efs write_batchtools_config(cluster['compute']) headfclient.put('batchtools.conf.R', '/efs/btrun/batchtools.conf.R') headclient.close() for c in cluster['compute']: cip = c['public'] nodeclient = pclient.SSHClient() nodeclient.set_missing_host_key_policy(pclient.AutoAddPolicy()) nodeclient.connect(cip, username='******', key_filename=kfn) exssh(nodeclient, 'sudo mkdir -p /efs') exssh(nodeclient, mntcmd) nodeclient.close()
def setup_nfs(cluster): write_exports(cluster['compute']) write_fstab(cluster['head']) headclient = pclient.SSHClient() headclient.set_missing_host_key_policy(pclient.AutoAddPolicy()) hip = cluster['head']['public'] kfn = cluster['key'] + '.pem' headclient.connect(hip, username='******', key_filename=kfn) headfclient = headclient.open_sftp() # Set up /etc/exports on head node headfclient.put('exports', '/home/ubuntu/exports') exssh(headclient, 'sudo cat /etc/exports /home/ubuntu/exports >/home/ubuntu/tmp') exssh(headclient, 'sudo mv /home/ubuntu/tmp /etc/exports') # exssh(headclient, 'sudo rm -f /home/ubuntu/exports') # exssh(headclient, 'sudo rm -f /home/ubuntu/tmp') # Make /scratch directory on head node exssh(headclient, 'sudo mkdir -p /scratch') exssh(headclient, 'sudo chown nobody:nogroup /scratch') exssh(headclient, 'sudo chmod -R 777 /scratch') # Push batchtools.conf.R to /scratch write_batchtools_config(cluster['compute']) headfclient.put('batchtools.conf.R', '/scratch/batchtools.conf.R') # Restart NFS server on head node exssh(headclient, 'sudo systemctl restart nfs-kernel-server') headfclient.close() headclient.close() for c in cluster['compute']: cip = c['public'] nodeclient = pclient.SSHClient() nodeclient.set_missing_host_key_policy(pclient.AutoAddPolicy()) nodeclient.connect(cip, username='******', key_filename=kfn) nodefclient = nodeclient.open_sftp() # Make /scratch directory on compute nodes exssh(nodeclient, 'sudo mkdir -p /scratch') exssh(nodeclient, 'sudo chmod -R 777 /scratch') # Append mount to /etc/fstab nodefclient.put('fstab', '/home/ubuntu/fstab') exssh(nodeclient, 'sudo cat /etc/fstab /home/ubuntu/fstab >/home/ubuntu/tmp') exssh(nodeclient, 'sudo mv /home/ubuntu/tmp /etc/fstab') exssh(nodeclient, 'sudo rm -f /home/ubuntu/fstab') # exssh(nodeclient, 'sudo rm -f /home/ubuntu/tmp') # Mount NFS export (note: access is slow for first write, maybe just reboot?) exssh( nodeclient, 'sudo mount ' + cluster['head']['private'] + ':/scratch /scratch') nodefclient.close() nodeclient.close()
def check_ssh(ip, port, user, private_key): try: cli = client.SSHClient() cli.load_host_keys("/dev/null") cli.set_missing_host_key_policy(client.AutoAddPolicy()) if private_key and user: print("[DEBUG-SSH] Trying pubkey auth for", ip) k = RSAKey.from_private_key_file(path + "checkfiles/" + private_key) cli.connect(ip, port, user, banner_timeout=20, timeout=20, auth_timeout=20, pkey=k) else: cli.connect(ip, port, "root", "Password3#", banner_timeout=20, timeout=20, auth_timeout=20) cli.close() return 1, None except Exception as e: if str(e) == "Authentication failed." and not private_key: return 1, None return 0, str(e)
def __init__(self, address, logger=logging): self.address = address self.username = os.environ.get('AMBARI_USER', 'smoketest') self.logger = logger self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy())
def __init__(self, address, port, username, pkey_file, passphrase): self.address = address self.port = port self.username = username self.pkey_file = RSAKey.from_private_key_file(pkey_file, passphrase) self.passphrase = passphrase self.client = client.SSHClient()
def run(options): ip = options['ip'] port = options['port'] username = options['username'] password = options['password'] try: cli = client.SSHClient() cli.load_host_keys('/dev/null') cli.set_missing_host_key_policy(client.AutoAddPolicy()) cli.connect(ip, port, username, password) return True except socket.timeout: logger.debug('Timeout') return False except AuthenticationException as e: error_string = ERROR_STRINGS[e.__class__.__name__] logger.debug(error_string % (username, password)) return False except (BadHostKeyException, SSHException, NoValidConnectionsError) as e: error_string = ERROR_STRINGS[e.__class__.__name__] logger.debug(error_string % e) return False except socket.error as e: logger.debug(ERROR_STRINGS[e.errno]) return False
def __init__(self, jump_host, remote_host): #create an open ssh client self.remote_host = remote_host self.host_ssh = pclient.SSHClient() self.host_ssh.load_system_host_keys() self.host_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.host_ssh.connect(jump_host, username='******')
def executeGCodeSFTP(gcodeFilePath): cnopts = pysftp.CnOpts() cnopts.hostkeys = None # And authenticate with private key with pysftp.Connection(host=BOARD_IP, username='******', password='******', cnopts=cnopts) as sftp: sftp.chdir("/root/SCARA_robot/src/") sftp.put(gcodeFilePath, remotepath="/root/SCARA_robot/src/test.gcode" ) # upload file to public/ on remote # print(sftp.execute("cd /root/SCARA_robot/src;python3 HPS_to_FPGA/CommandStreamTest.py")) #result = sftp.execute(SCRIPT_EXECUTE) #print(result) client = ssh.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(ssh.AutoAddPolicy()) client.connect(hostname=BOARD_IP, port=22, username="******", password="******") stdin, stdout, stderr = client.exec_command( "cd /root/SCARA_robot/src; python3 main.py") return (stdout.read().decode(), stderr.read().decode())
def __init__(self, address, username, password): self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, password=password, look_for_keys=True)
def __init__(self): print("Connecting to server.") self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy) self.client.connect('192.168.33.10', username='******', password='******')
def __init__(self, address, username, password): print("Connecting to server.") self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, password=password, look_for_keys=False) self.transport = paramiko.Transport((address, 22)) self.transport.connect(username=username, password=password)
def __init__(self, address): self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=config('SSHUSER'), password=config('SSHPASSWORD'), look_for_keys=False)
def symlink(self, destination_dir_name, original, callback): cl = client.SSHClient() cl.load_system_host_keys() cl.connect(self.server, username=self.user) stdin, stdout, stderr = cl.exec_command('ln -s {} {}'.format( original, self._path_to + destination_dir_name)) callback()
def __init__(self, logindetails): self.__ip = logindetails['ip'] self.__username = logindetails['username'] self.__password = logindetails['password'] self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(self.__ip, username=self.__username, password=self.__password, look_for_keys=False)
def delete_srt(self, cfg): """ Delete the srt file in all the RM instances. :param cfg: :return: """ isaws = False if sys.argv[1].startswith('aws'): isaws = True if isaws: rrhosts = self.consul_activity_srt(cfg) else: rrhosts = [cfg["rm"]["host"]] print "RRs in which SRT file will be deleted : ", rrhosts # Establishing the remote connection to RRs with paramiko to push customized the SRT file. for rr in rrhosts: print "Deleting the SRT file in : ", rr client1 = client.SSHClient() client1.set_missing_host_key_policy(paramiko.AutoAddPolicy()) if isaws: client1.connect(rr, username="******", allow_agent=True) else: client1.connect(rr, username="******", password="******", look_for_keys=False, allow_agent=True) client1.exec_command( "sudo rm -f /opt/cisco/gosrm/ConfigFiles/rioRecorder/static_route_table.txt" ) client1.close() print "Successfully deleted the SRT file in all the rr instances."
def connect(self, instance): """Opens an SSH connection to this instance.""" client = sshclient.SSHClient() client.set_missing_host_key_policy(sshclient.AutoAddPolicy()) client.connect(instance.ip_address, username="******", key_filename=self._ssh_keyfile) return client
def __init__(self, address, username, password): print('Connecting to server.') self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, password=password, look_for_keys=False)
def __init__(self, address, username, key_filename): print('connecting to {} ...'.format(address)) self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, key_filename=key_filename) print("connected ....")
def __init__(self, address): username = '******' keyfile = '/root/.ssh/112_rsa.pub' # Create a new SSH client self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) # Make the connection self.client.connect(address, username=username, key_filename=keyfile)
def __init__(self, address): username = '******' # keyfile = '/root/.ssh/id_dsa.pub' # Create a new SSH client self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) # Make the connection self.client.connect(address, username=username, password='******')
def __init__(self, address, username, password): print("******Connecting to the 3PAR Machine...******") self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, password=password, look_for_keys=False)
def __init__(self,address): logging.info ("Log Validation Script") logging.info ("connecting to server \n : ", address) self.client=client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) privatekeyfile = os.path.expanduser('~/.ssh/id_rsa') mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile) self.client.connect(address, username='******', pkey = mykey)
def __init__(self, hostname, username, password, logger=None): self.logger = logger or logging self.client = ssh = pmclient.SSHClient() ssh.set_missing_host_key_policy(pmclient.AutoAddPolicy()) self.logger.debug("SSHClient: Connecting to %s with %s and password", hostname, username) ssh.connect(hostname, username=username, password=password, look_for_keys=False)
def __init__(self, address, username, password): self.address = address self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, password=password, look_for_keys=False) self.Ts_sendCommand = []
def __init__(self, address, username, password): # Let the user know we're connecting to the server print("Connecting to server.") # Create a new SSH client self.client = client.SSHClient() # The following line is required if you want the script to be able to access a server that's not yet in the known_hosts file self.client.set_missing_host_key_policy(client.AutoAddPolicy()) # Make the connection self.client.connect(address, username=username, password=password, look_for_keys=False)
def SSH(HOST,USER,PASS): try: client1=client.SSHClient() client1.set_missing_host_key_policy(client.AutoAddPolicy()) client1.connect(HOST,username=USER,password=PASS,port=22,look_for_keys=False) print ("SSH connection to %s established" %HOST) except IOError: print("There was an error connecting to host",HOST) return client1;
def __init__(self, address, username): self.logger = logging.get_logger(self.__class__.__name__) self.logger.info("Connecting to server {}.".format(address)) self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, key_filename=os.path.join(os.path.expanduser("~"), ".ssh", "id_rsa"))
def __init__(self, address, username, password): print("Connecting to server through SSH") self.client = client.SSHClient() # following line is required if you want the script to be able to access a server that's not yet in the known_hosts file self.client.set_missing_host_key_policy(client.AutoAddPolicy()) # make the connection self.client.connect(address, username=username, password=password, look_for_keys=False)
def __init__(self, address, username, password, port='22'): self.address = address self.username = username self.client = client.SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(address, username=username, password=password, look_for_keys=False, port=port)
def __init__(self, address, username, password, port=22): # print "Connecting to server ", str(address)+":"+str(port) self._client = client.SSHClient() self._client.set_missing_host_key_policy(client.AutoAddPolicy()) self._client.connect( address, port=port, username=username, password=password, look_for_keys=False )