【发布时间】:2019-03-15 03:35:45
【问题描述】:
我正在使用 subprocess.Popen 创建一个 ssh 隧道。然而,为了成功创建这个隧道,我使用了一个 Yubikey,它需要一个 pin 来释放成功验证的密钥,内置 ssh 配置。下面的代码是我能得到的。
def launch_tunnel(self):
try:
enterpin = getpass.getpass()
bytepin = str.encode(enterpin)
launchtunnel = subprocess.Popen('ssh tunnel command',
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE
stderr=subprocess.PIPE).communicate(input=bytepin)
except Exception as e:
print(e)
当我运行它时,我得到以下 2 个提示。
Password:
Enter PIN for 'PIV_II (PIV Card Holder pin)':
第一个是 getpass.getpass(),第二个是另一个需要 Yubikey Pin 的进程。很明显 .communicate() 在这里不起作用,据我所知,这是因为 ssh 进程产生了另一个需要 ssh 身份验证的进程(pin 提示符)。
是否可以在使用 getpass 之类的方法之前设置引脚并将其直接传递给第二个进程。目前这第二个进程(pin 提示)正在中断我的应用程序的其余部分,所以我想控制它?
【问题讨论】:
标签: python-3.x ssh subprocess popen tunnel