linux - 密码作为 sshpass 命令的输入
问题描述
sshpass
我已经为我的办公室使用编写了一个 bash 脚本,以使用命令从设备中获取一些信息ssh
。正如我们所知sshpass
,允许使用-p
选项在命令行上传递密码,这使得密码可见,因此我想要一个需要在屏幕本身上作为用户输入提示的密码。
下面的脚本工作正常,但我需要在屏幕上提示用户输入密码。请告知如何做到这一点,因为我已经搜索过但没有得到任何具体答案。
#!/bin/bash
#
# timestamp to be attached to the log file
TIMESTAMP=$(date "+%Y%m%d%H%M%S")
# logfile to collect all the Firmware Version of C7000 components
LOGFILE="/home/myuser/firmware_version-${TIMESTAMP}.log"
for host in $(cat enc_list);
do
echo "========= $host =========";
sshpass -p my_password timeout -t 20 ssh -o "StrictHostKeyChecking no" $host -l tscad show firmware summary ;
done | tee -a "${LOGFILE}"
解决方案
避免在命令行中输入密码:
read -r -s -p "Password:" SSHPASS
export SSHPASS
sshpass -e timeout ... ssh ...
来自man sshpass
:
-e
:密码取自环境变量“SSHPASS”。
推荐阅读
- python - 停止时钟,从绿色开始,在 5 分钟变为黄色,然后在 10 分钟后再次变为红色
- javascript - 如何使用“timeupdate”事件侦听器突出显示音频中的文本?
- flexdashboard - heatmaply + flexdashboard = validateCssUnit(sizeInfo$width) 中的错误:CSS 单位必须是单元素数字或字符向量
- r - 如果在它旁边的列中为 n/a,则替换为 n/a
- sql - sqlite中的'ON REPLACE CASCADE'
- python - 获取字符串的最后一个字符
- python - 在python中实现协程
- javascript - 1小时后如何获取localStorage setItem?
- c# - 如何根据asp.net c#中更改的先前下拉数据更改下拉列表?
- assembly - 是什么导致此引导加载程序在硬件上失败但在 DOSBOX 中失败?它显示所有寄存器