我想知道当我ssh-keygen
通过使用subprocess
或不调用脚本时是否需要做一些不同的事情。我在 Linux 环境中运行。这是我的代码:
cfg_r = configparser.ConfigParser()
cfg_r.read('ssh_config.cfg')
p_mail=cfg_r.get('Company', 'mail')
bashCo m mand="ssh-keygen -t rsa -f /home/pi/.ssh/id_rsa - C \"{}\" -q -N \"\"".format(p_mail)
print(bashCommand.split())
proc = subprocess.Popen(bashCommand.split(),
stdout=subprocess.PIPE,
stderr=open('logfile_Get_conf.log', 'a'),
preexec_fn=os.setpgrp
)
outpu.stdout.read().decode('utf-8')
configparser
除了这个,我经常阅读电子邮件,没什么特别的。
bashCommand
应该是这样:
ssh-keygen -t rsa -f /home/pi/.ssh/id_rsa -C "mail@gmail.com" -q -N ""
bashCommand.split()
也应该如此:
['ssh-keygen', '-t', 'rsa', '-f', '/home/pi/.ssh/id_rsa', '-C', '"mail@gmail.com"', '-q', '-N', '""']
非常奇怪的是,当我bashCommand
在 shell 中运行它时,没有出现任何问题:
ssh-keygen -t rsa -f /home/pi/.ssh/id_rsa -C "mail@gmail.com" -q -N ""
但是在我的日志文件中我仍然有这个错误:
Saving key "/home/pi/.ssh/id_rsa" failed: passphrase is too short (minimum five characters)
问题出在哪里?