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 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 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, output_dir: str): assert exists(output_dir), "Output dir {} does not exist.".format( output_dir) self._output_dir = output_dir ssh_config = SSHConfig() user_config_file = os.path.expanduser("~/.ssh/config") if os.path.exists(user_config_file): with open(user_config_file) as f: ssh_config.parse(f) self._ssh_client = SSHClient() self._ssh_client.set_missing_host_key_policy(client.AutoAddPolicy()) # self._ssh_client. self._ssh_config = ssh_config.lookup('minicup') self._ssh_client.load_system_host_keys() self._ssh_config = { "hostname": self._ssh_config["hostname"], "username": self._ssh_config["user"], # "port": int(self._ssh_config["port"]), 'key_filename': self._ssh_config['identityfile'] } self._ssh_client.connect(**self._ssh_config)
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 openconnection(self): if (self.grid_params["short_name"] == "hopper" or self.grid_params["short_name"] == "edison"): print "connecting ", self.grid_params["short_name"] self.client = SSHClient() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.load_system_host_keys() self.client.connect(self.grid_params["full_name"], allow_agent=True) self.sftp = self.client.open_sftp() else: proxy_command = 'ssh %s nc %s %s' % ( 'aluf.technion.ac.il', self.grid_params["full_name"], 22) proxy = ProxyCommand(proxy_command) self.client = SSHClient() self.client.load_system_host_keys() self.client.connect(self.grid_params["short_name"], sock=proxy, allow_agent=True) self.sftp = self.client.open_sftp() stdin, stdout, stderr = self.client.exec_command("pwd") home = stdout.readlines()[0].rstrip() print home self.grid_params['home'] = home print "Connection Open"
def connect(self, connectTimeout=10, serverPrompt="$|#", breakCharacter="|", term="vt100"): try: term = term if term in ["vt100", "dumb"] else "dumb" self.client.load_system_host_keys() self.client.set_missing_host_key_policy(client.AutoAddPolicy()) self.client.connect(self.ip, port=self.port, username=self._username, password=self._password, look_for_keys=False, timeout=connectTimeout) self.logger.debug("connected") self.channel = self.client.invoke_shell(term=term, width=1600, height=1200) t = threading.Thread(target=self.onReceiveData) t.start() if serverPrompt is not None: self.wait(serverPrompt, breakCharacter) except Exception as e: raise e
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, 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 __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 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, 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 __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 install_monet(): print "in scp client" print "copying Monet installation file" Username = "******" Password = "******" Server = "192.168.56.20" ssh = SSHClient() ssh.set_missing_host_key_policy(client.AutoAddPolicy()) ssh.connect(Server, username=Username, password=Password) # SCPCLient takes a paramiko transport as its only argument scp = SCPClient(ssh.get_transport()) scp.put('6.125/Monet.6.125.solaris11.amd64.run', '/tmp/Monet.6.125.solaris11.amd64.run') #scp.get('/var/tmp/tdir','c:/temp',recursive=True) print "scp done" scp.close() print "executing Monet Install file" command = "(chmod +x /tmp/Monet*;/tmp/Monet.6.125.solaris11.amd64.run)" output, error = connection.run_Cmd_stderr(command)
def executeSSHcommand(self,command,continousAttempt=True,max_tries=10,sudo=False): tries=0 while True: try: ssh = SSHClient() ssh.set_missing_host_key_policy(client.AutoAddPolicy()) ssh.connect(self.targetHostname, username=self.targetSSHusername, password=self.targetSSHpassword) stdin, stdout, stderr = ssh.exec_command(command) if sudo: stdin.write(self.targetSSHpassword + "\n") stdin.flush() lines=[] for line in stdout.readlines(): lines.append(line) ssh.close() return lines except: if continousAttempt and tries<max_tries: tries=tries+1 continue else: raise("Exception: Unable to execute command "+str(command))
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, 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): 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 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 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 Start_Async_Show(self, host, user, passwd): ssh = SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(client.AutoAddPolicy()) ssh.connect(host, port=22, username=user, password=passwd, timeout=30) channel = ssh.invoke_shell() channel.exec_command("show router bgp routes | match Routes") ssh.close()
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, 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 = '******' # 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): 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)