Linux Mac 下终端记住ssh密码

编写ssh连接脚本

vim ~/.ssh/new.ssh
  • 添加以下内容
#!/usr/bin/expect -f

set user "root"
set host "127.0.0.1"
set password "yourpassword"
set port 22

spawn ssh $user@$host -p $port
expect "password:*"
send "$password\r"
interact
expect eof

终端配置开启后自动执行命令

expect ~/.ssh/new.ssh
评论