如何使用authorized_keys。然后,您无需输入密码。
您也可以采用艰难的方式(仅适用于Linux):
import osimport ptydef wall(host, pw): pid, fd = pty.fork() if pid == 0: # Child os.execvp('ssh', ['ssh', host, 'ls', '/usr/bin/wall']) os._exit(1) # fail to execv # read '..... password:', write password os.read(fd, 1024) os.write(fd, pw + 'n') result = [] while True: try: data = os.read(fd, 1024) except OSError: break if not data: break result.append(data) pid, status = os.waitpid(pid, 0) return status, ''.join(result)status, output = wall('localhost', "secret")print statusprint outputhttp://docs.python.org/2/library/pty.html



