我有一个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
给出命令后,会询问位置和密码(两次)。在交互式外壳中,我通常会做的就是按enter 三下。但是在这里,由于我连接到master
by 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
文件吗?
任何帮助表示赞赏!