VANHOR
V2EX  ›  问与答

关于 Mac 上的终端 iTerm2 的问题

  •  
  •   VANHOR · Jun 21, 2019 · 2657 views
    This topic created in 2693 days ago, the information mentioned may be changed or developed.
    想配置一下 iTerm2 连接服务器的快捷命令,上网查了半天,只找到单纯用密码登陆的,但是公司的服务器是有一个动态口令,目前没找到怎么先让我输入动态口令再自动输入密码的脚本...有人知道吗?

    目前是这样配置的

    #!/usr/bin/expect

    set PORT 22
    set HOST ***.**.12.20
    set USER root
    set PASSWORD ************

    spawn ssh -p $PORT $USER@$HOST
    expect {
    "yes/no" {send "yes\r";exp_continue;}
    "*password:*" { send "$PASSWORD\r" }
    }
    interact
    12 replies  •  2019-06-21 20:23:07 +08:00
    Hilong
    Hilong
    Jun 21, 2019 via Android
    1
    这个和 item2 有啥关系。就是 shell 脚本啊。你在自动填充密码前加一个输入动态口令的输入不就行了。
    hhyvs111
    hhyvs111
    Jun 21, 2019
    2
    在 profiles 里配置,general 里有一个 send text at start,输入你的脚本调用,然后输入跳板机动态密码后就可以自动执行你这个脚本。
    xuuuu
    xuuuu
    Jun 21, 2019
    3
    可以试试 iTerm2 的 password manager
    VANHOR
    VANHOR
    OP
    Jun 21, 2019
    4
    @Hilong 试了半天,总写不对...
    Melodyer
    Melodyer
    Jun 21, 2019
    5
    ``` bash
    #!/usr/bin/expect -f
    set port 1234
    set user root
    set host 67.xx.xx.xx
    set password xxxxxx
    set timeout -1

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

    ```
    上面是我平时用的,针对第一次的 yes 没有处理,先手动 ssh 一次以后直接可以用这个脚本。
    Melodyer
    Melodyer
    Jun 21, 2019
    6
    @Melodyer 居然不支持 Markdown,去掉第一行 ```bash 和最后一行 ```。
    Melodyer
    Melodyer
    Jun 21, 2019
    7
    哇,没看到楼主的需求,忽略我发的。。
    singerll
    singerll
    Jun 21, 2019 via Android
    8
    xshell 就没这种烦恼了。。。
    VANHOR
    VANHOR
    OP
    Jun 21, 2019
    9
    @singerll 是....Mac 下比较麻烦
    VANHOR
    VANHOR
    OP
    Jun 21, 2019
    10
    @Melodyer 嗯那没事,还是谢谢你。
    VANHOR
    VANHOR
    OP
    Jun 21, 2019
    11
    @xuuuu 试了下,感觉这个可以。( :
    Jackxun123
    Jackxun123
    Jun 21, 2019
    12
    推荐 sshpass
    https://www.cnblogs.com/onlyfu/p/4460160.html
    写脚本也是可以的,不过还是要去加参数
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1316 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 21:06 · PVG 05:06 · LAX 13:06 · JFK 16:06
    ♥ Do have faith in what you're doing.