sshpass: 用于非交互的ssh 密码验证
ssh登陆不能在命令行中指定密码,也不能以shell中随处可见的,sshpass 的出现,解决了这一问题。它允许你用 -p 参数指定明文密码,然后直接登录远程服务器。 它支持密码从命令行,文件,环境变量中读取
$> sshpass -h Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters -f filename Take password to use from file -d number Use number as file descriptor for getting password -p password Provide password as argument (security unwise) -e Password is passed as env-var "SSHPASS" With no parameters - password will be taken from stdin -h Show help (this screen) -V Print version information At most one of -f, -d, -p or -e should be used
sshpass [-f|-d|-p|-e] [-hV] command parameters 中的 command parameters 和使用交互式密码验证的使用方法相同
#从命令行方式传递密码
$> sshpass -p user_password ssh user_name@192.168..1.2 $> sshpass -p user_password scp -P22 192.168.1.2:/home/test/t .
#从文件读取密码
$> echo "user_password" > user.passwd $> sshpass -f user.passwd ssh user_name@192.168..1.2
#从环境变量获取密码
$> export SSHPASS="user_password" $> sshpass -e ssh user_name@192.168..1.2
对于ssh的第一次登陆,会提示:
“Are you sure you want to continue connecting (yes/no)”,这时用sshpass会不好使,可以在ssh命令后面 -o StrictHostKeyChecking=no
来解决。比如说上面的命令,就可以写作
ssh abc@192.168.1.100 -o StrictHostKeyChecking=no
“Are you sure you want to continue connecting (yes/no)”,这时用sshpass会不好使,可以在ssh命令后面 -o StrictHostKeyChecking=no
来解决。比如说上面的命令,就可以写作
ssh abc@192.168.1.100 -o StrictHostKeyChecking=no
PS:
源码位置:http://sourceforge.net/projects/sshpass/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架