企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 概述 - sshpass 是非交互式密码验证命令行工具 - sshpass 可用于 `ssh` 与`scp` 重要:使用**sshpass**是最不安全的,通过 `ps`命令可以查看密码,推荐使用[SSH 无密码身份验证](https://linux.cn/article-6901-1.html)。 ## 安装 ``` yum install sshpass sudo apt-get install sshpass // 源码安装 $ wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz $ tar -xvf sshpass.tar.gz $ cd sshpass-1.06 $ ./configure # sudo make install ``` ## 场景 ### hello word ssh ``` sshpass -p 'my_pass_here' ssh idcpj@10.42.0.1 'df -h' ``` scp ``` sshpass -p 'my_pass_here' scp demo.txt idcpj@10.42.0.1:~/ ``` ### 在环境变量设置密码(安全) ``` export SSHPASS='my_pass_here' sshpass -e ssh idcpj@10.42.0.1 'df -h' ``` ### 在文件中设置密码 ``` sshpass -f password_filename ssh idcpj@10.42.0.1 'df -h' ```