sshpass y用法

简介

# 自动在 SSH 登录提示符中提供密码
# 重要:使用 sshpass 是最不安全的,ps命令就可看到密码

安装

yum install sshpass
# dnf install sshpass
# apt install sshpass

测试实例

# and ssh
sshpass -p 'my_passwd' ssh root@10.42.0.1 'df -h'
# and scp
sshpass -p 'my_passwd' scp -rp xxx.tar.gz root@192.156.1.6:/backup/
# and rsunc
sshpass -p 'my_passwd' rsync -a /root/xxx.tar.gz root@192.168.0.12:/tmp/

密码保护

# sshpass -e 变量密码
export SSHPASS='my_passwd' >>/etc/profile
source /etc/profile
sshpass -e 'my_passwd' ssh root@10.42.0.1 'df -h'
# sshpass -f 文件读密码
echo "my_passwd" >>/root/my_passwd.txt
sshpass -f /root/my_passwd.txt ssh root@10.42.0.1 'df -h'

posted on 2025-11-04 14:27  luokeli  阅读(6)  评论(0)    收藏  举报

导航