【发布时间】:2026-01-26 10:50:01
【问题描述】:
我正在尝试自动化我的 ancible 部署只是想了解更多信息,我试图在复制 ssh 密钥时自动插入机器的密码但是它仍然每次都提示我输入密码,我不知道为什么,也许它在提示之前发送密钥我不确定..
#!/bin/bash
apt-get update --force-yes
apt-get install software-properties-common -y --force-yes
apt-add-repository ppa:ansible/ansible -y --force-yes
apt-get update -y --force-yes
apt-get install ansible -y --force-yes
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
ssh-copy-id root@0.0.0.0
send("mypass{enter}")
【问题讨论】:
-
send是expect命令而不是 shell 命令。你不能就这样使用send。 -
@EtanReisner 那你建议我怎么做?
-
如果你想使用
expect,那么你使用expect。如果你不设置 ssh 密钥。如果您不能/不想这样做,您也可以查看sshpass但是键是最好的方法。 -
期望如何使用?
-
Oz123 的回答是为此目的的期望脚本的一个合理示例。