我有一个lxd
容器master
,它有一个IP 10.154.151.8
。我想通过我的机器上的ssh
对它执行ssh-keygen
。也就是说
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中,我通常只需按三次回车键。但是在这里,因为我通过ssh
连接到master
,所以我不能这样做。输出为:
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
文件?你知道吗
感谢您的帮助!你知道吗
不要试图模拟用户输入。你知道吗
使用^{} 和^{} 的^{} 命令行开关:
相关问题 更多 >
编程相关推荐