【发布时间】:2020-02-12 15:20:35
【问题描述】:
我在编写 Python 脚本时遇到问题,该脚本对/.ssh/id_rsa 文件进行暴力破解 SSH 私钥密码短语。我正在使用ssh-add 命令询问密码,直到您输入为止。
但脚本失败并出现错误:
ssh_askpass: exec(/usr/bin/ssh-askpass): 没有那个文件或目录
我不明白为什么。
使用.Popen、.call 等尝试了所有子流程模块的变体。但我认为最适合我的情况是:
import subprocess
p = subprocess.Popen('ssh-add id_rsa', stdin=subprocess.PIPE, text=True, shell=True)
p.stdin.write(str('password'))
预期的密码请求,例如"Enter passphrase for id_rsa"
【问题讨论】:
标签: python ssh subprocess ssh-keys brute-force