最新消息:

sshmenu

SSH admin 2087浏览 0评论

如果你还在使用 iTerm, alias 管理 服务器, 可以试试下面 sshmenu

安装 sshmenu

# git clone https://github.com/selboo/sshmenu.git
# cd sshmenu
# python setup.py install

/root/sshmenu.json

 # cat /root/sshmenu.json
{
    "targets": [
        {
            "host": "selboo@192.168.1.100",
            "command": "/bin/ssh",
            "friendly": "pi",
            "options": [
                "-p60777",
                "-i/root/.ssh/selboo_id_rsa",
                "-F/root/env/ssh/config",
                "-oStrictHostKeyChecking=no",
                "-oConnectTimeout=3"
            ]
        },
        {
            "host": "aikaiyuan@www.aikaiyuan.com",
            "command": "/bin/ssh.sh",
            "friendly": "vps usa",
            "options": [
                "password123",
                "-oStrictHostKeyChecking=no",
                "-oConnectTimeout=3"
            ]
        },
        {
            "host": "root@192.168.199.100",
            "command": "/bin/ssh.sh",
            "friendly": "pi 4B",
            "options": [
                "mima321",
                "-oStrictHostKeyChecking=no",
                "-oConnectTimeout=3"
            ]
        },
        {
            "host": "root@1.1.1.200",
            "command": "/bin/ssh.sh",
            "friendly": "test server",
            "options": [
                "1234567890",
                "-p65500",
                "-oTCPKeepAlive=yes",
                "-oStrictHostKeyChecking=no",
                "-oServerAliveInterval=30",
                "-oConnectTimeout=3"
            ]
        }
    ]
}
  • host: [user]@[host|ip]
  • command: /bin/ssh or /bin/ssh.sh
  • friendly: 备注
  • options:
    1. 第一行是密码
    2. -p: 端口
    3. -oTCPKeepAlive=yes : 保持回话
    4. -oStrictHostKeyChecking=no 不检查known_hosts
    5. -oServerAliveInterval=30 : 保持回话
    6. -oConnectTimeout=3: 连接超时
    7. 更多配置可以 man ssh

/bin/ssh.sh

#!/usr/bin/expect

set timeout 20

set cmd [lrange $argv 1 end]
set password [lindex $argv 0]

eval spawn "ssh $cmd"
sleep 1
expect "(yes/no)?" {
    send "yes\r"
    expect "*assword:"
    send "$password\r";
} "*assword:" {
    send "$password\r";
} "*assword: " {
    send "$password\r";
} "*assword:" {
    send "$password\r";
} "# " {
    send "";
} "$ " {
    send "";
}

interact

/root/env/ssh/config

Host *
    ControlMaster auto
    ControlPath /tmp/%r@%h
    ControlPersist 86400

重用 SSH 连接

启动

# alias myssh="sshmenu -c /root/sshmenu.json"
# myssh
Select a target (press "h" for help)
    ID User                        | Host                        | Note                        | Login
 ->  1 selboo                      | 192.168.1.100               | pi                          | No
     2 aikaiyuan                   | www.aikaiyuan.com           | vps usa                     | No
     3 root                        | 192.168.199.100             | pi 4B                       | No
     4 root                        | 1.1.1.200                   | test server                 | No

转载请注明:爱开源 » sshmenu

您必须 登录 才能发表评论!