我有一个lxd
容器master
,它有一个IP 10.154.151.8
。我想从我的机器ssh-keygen
上执行它ssh
。
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.154.151.8',username='root')
stdin,stdout,stderr = ssh.exec_command('ssh-keygen')
我在这里面临的问题是,在ssh-keygen
给出命令后,会询问位置和密码(两次)。我通常会做的就是在交互式shell中按enter 三次。但在这里,由于我已经接master
通过ssh
,我不能这样做。输出是:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rohit/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rohit/.ssh/id_rsa.
Your public key has been saved in /home/rohit/.ssh/id_rsa.pub.
The key fingerprint is:
所以我试着这样做:
stdin.write("\n")
stdin.write("\n")
stdin.write("\n")
但那并没有创建id_rsa.pub
文件。
同样我试过:
stdin.write("")
stdin.write("")
stdin.write("")
但这也不起作用。
那么,我在这里做错了什么?
此外,有没有其他方式(paramiko
优选使用),生成id_rsa.pub
文件?
任何帮助表示赞赏!
发布于 2019-04-15 13:41:22
https://stackoverflow.com/questions/-100009011
复制相似问题