linux输入密码时采用非交互式
linux输入密码时采用非交互式
-
sshpass
- 安装sshpass
apt-get install sshpass
- 示例
sshpass -p "123456" root@192.168.1.4 #ssh登录 sshpass -p "123456" root@192.168.1.4:/opt/share/* ./test/ #将远端的文件拷贝到本地test目录下
-
备注
# scp时取消yes/no回答 ssh -o StrictHostKeyChecking=no root@192.168.1.4
-
expect
-
安装expect
apt-get install expect
-
示例
#!/usr/bin/expect set user [lindex $argv 0] set ip [lindex $argv 1] set password [lindex $argv 2] spawn ssh $user@$ip "df -Th" expect { "yes/no" {send "yes\r"; exp_continue} "password" {send "$password\r"} } expect eof
-