Tag: paramiko

如何通过公钥与python Paramiko连接

我使用Paramiko通过SSH连接到服务器。 基本身份validation运作良好,但我不明白如何连接公钥。 当我连接腻子,服务器告诉我这一点: Using username "root". Authenticating with public key "rsa-key@ddddd.com" Passphrase for key "rsa-key@ddddd.com": [i've inserted the passphrase here] Last login: Mon Dec 5 09:25:18 2011 from … 我用这个ppk文件连接到它: PuTTY-User-Key-File-2: ssh-rsa Encryption: aes256-cbc Comment: rsa-key@dddd.com Public-Lines: 4 [4 lines key] Private-Lines: 8 [8 lines key] Private-MAC: [hash] 使用基本身份validation我得到的错误(从日志)是: DEB [20111205-09:48:44.328] thr=1 paramiko.transport: userauth is […]

如何使用Paramiko获得SSH返回码?

client = paramiko.SSHClient() stdin, stdout, stderr = client.exec_command(command) 有什么办法可以得到命令的返回码吗? 很难parsing所有的标准输出/标准错误,并知道命令是否成功完成。

如何在Paramiko的单个会话中执行多个命令? (python)

def exec_command(self, command, bufsize=-1): #print "Executing Command: "+command chan = self._transport.open_session() chan.exec_command(command) stdin = chan.makefile('wb', bufsize) stdout = chan.makefile('rb', bufsize) stderr = chan.makefile_stderr('rb', bufsize) return stdin, stdout, stderr 当在paramiko中执行一个命令时,它会在运行exec_command时重置会话。 我希望能够执行sudo或su,并且在运行另一个exec_command时仍然具有这些权限。 另一个例子是尝试exec_command(“cd /”),然后再次运行exec_command并将其放在根目录中。 我知道你可以做一些像exec_command(“cd /; ls -l”),但我需要在单独的函数调用。

在Paramiko中运行交互式命令

我试图通过paramiko运行一个交互式命令。 cmd执行尝试提示input密码,但我不知道如何通过paramiko的exec_command提供密码,执行挂起。 如果cmd执行需要交互式input,有没有办法将值发送到terminal? ssh = paramiko.SSHClient() ssh.connect(server, username=username, password=password) ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("psql -U factory -d factory -f /tmp/data.sql") 有谁知道这可以解决? 谢谢。