0

应用解决方案时

ssh-keygen -t rsa -N "" -f my.key

在 Python 3中自动为 bash 脚本生成 ssh 键的“输入”按键我偶然发现了以下问题:

sp.check_call(["ssh-keygen", "-t", "rsa", "-N", "\"\"", "-f", "my.key"])

sp.check_call(["ssh-keygen", "-t", "rsa", "-N", "''", "-f", "my.key"])

由于失败

Saving key "my.key" failed: passphrase is too short (minimum five characters)

sp.check_call(["ssh-keygen", "-t", "rsa", "-N", "", "-f", "my.key"])

导致ssh-keygen提示输入应该通过传递来避免的键-N ""

实现命令接收的pythonic方式是什么-N ""?我知道将命令和参数作为一个字符串传递的可能性,这可能会解决这个问题,或者从参考问题的答案中采取另一种方法。我想拓宽我的 Python 知识。

4

1 回答 1

0
sp.check_call(["ssh-keygen", "-t", "rsa", "-N", "", "-f", "my.key"])

works on the command line as well as in the Docker image python:3, but not when the code is invoked in a script which is invoke with python3 script.py inside the Docker image google/cloud-sdk.

That's interesting, but probably caused by different behaviour if tty is missing as stated in some comments.

于 2019-07-20T17:24:45.193 回答