SSH keygen错误:'密码太短:有2个字节,需要> 4'

Baw*_*awn 1 python ssh

我正在尝试自动生成SSH RSA密钥的过程.当在命令行上运行以下命令时,它会正确生成密钥:

ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''
Run Code Online (Sandbox Code Playgroud)

当我尝试在python 2脚本中复制它时出现问题.

 if not os.path.isfile('/root/.ssh/id_rsa.pub'):
    fullcmd = ['ssh-keygen', '-f', '/root/.ssh/id_rsa', '-t', 'rsa', '-N', '\'\'']
    sshcmd = subprocess.Popen(fullcmd,
                shell= False,
                stdout= subprocess.PIPE,
                stderr= subprocess.STDOUT)
    out = sshcmd.communicate()[0].split('\n')
    for lin in out:
        print lin
Run Code Online (Sandbox Code Playgroud)

当我运行此脚本时,我收到此错误:

> passphrase too short: have 2 bytes, need >4
> Generating public/private
> rsa key pair. Saving the key failed: /root/.ssh/id_rsa.
Run Code Online (Sandbox Code Playgroud)

当我在命令行而不是通过python脚本执行它时,为什么要使用它?

Joh*_*ica 7

fullcmd = ['ssh-keygen', '-f', '/root/.ssh/id_rsa', '-t', 'rsa', '-N', '\'\'']
Run Code Online (Sandbox Code Playgroud)

''是用于传递空字符串的shell语法.您是直接调用命令,而不是通过shell调用,因此不要传递单引号.只需传递空字符串本身.

fullcmd = ['ssh-keygen', '-f', '/root/.ssh/id_rsa', '-t', 'rsa', '-N', '']
Run Code Online (Sandbox Code Playgroud)