ubuntu linux ssh 自动输入密码
第一种方法,直接使用expect脚本:
#!/usr/bin/expect -f
spawn ssh myname@192.168.1.5
expect "assword"
set timeout 300
send "mypassword\r"
interact
注意:#!/usr/bin/expect -f 这一句一定要写在文件第一行
另外:expect 的安装 用 sudo apt-get install expect 安装
第二种方法,使用shell脚本
#!/bin/bash
function myssh {
expect -c "
set user maname
set passwd mypassword
set remote_ip 192.168.1.5
spawn ssh \$user@\$remote_ip
expect {
"assword" {set timeout 300; send \"\$passwd\r\"}
}
interact
"
}
myssh
exit
注意:这用写法实质也是使用expect
第一种方法,直接使用expect脚本:
#!/usr/bin/expect -f
spawn ssh myname@192.168.1.5
expect "assword"
set timeout 300
send "mypassword\r"
interact
注意:#!/usr/bin/expect -f 这一句一定要写在文件第一行
另外:expect 的安装 用 sudo apt-get install expect 安装
第二种方法,使用shell脚本
#!/bin/bash
function myssh {
expect -c "
set user maname
set passwd mypassword
set remote_ip 192.168.1.5
spawn ssh \$user@\$remote_ip
expect {
"assword" {set timeout 300; send \"\$passwd\r\"}
}
interact
"
}
myssh
exit
注意:这用写法实质也是使用expect