iTerm2 ssh 自动登陆脚本

新建一个shell文件,如ssh_setting/autologin.sh

#!/usr/bin/expect

set timeout 30
set host [lindex $argv 0]
#  This line is to set a variable , Variable names can be used casually , Try to make sense , The parameters passed in are shown later ,0  Represents the first parameter , We'll use that later .
set port [lindex $argv 1]
set user [lindex $argv 2]
set pswd [lindex $argv 3]

spawn ssh -p $port $user@$host
# spawn  yes  expect  Internal command of the environment , Its main function is to  ssh  Add a shell to the running process , Used to pass interactive instructions .

expect {
        "(yes/no)?"
        {send "yes\n";exp_continue;}
	      -re "(p|P)ass(word|wd):"
        {send "$pswd\n"}
}
# expect  It's also  expect  An internal command of the environment , It is used to judge whether the output after the last instruction input contains  ""  String in double quotes ,-re  Means match by regularity .
#  If it's the first time to log in , There will be  "yes/no"  String , Is sent (send) Instructions  "yes\r", Then continue to (exp_continue).

interact
# interact: Keep interactive after execution , Give control to the console

然后在iterm2里设置profile,脚本参数依次是ip,port,host,password
在这里插入图片描述
在这里插入图片描述
再编辑一个触发器

Are you sure you want to continue connecting (yes/no)?

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值