• autossh使用(本机记住ssh密码)


    autossh版本说明

    目前发现同样叫autossh的,有好几个项目

    • yum,brew中的自动重启ssh会话和隧道
    • FeeiCN的autossh
    • islenbo的autossh

    后面两个的主要是用于记录密码,远程连接

    Feeicn版安装使用

    安装依赖:

    Linux
    yum install expect
    apt-get install expect
    

    安装autossh

    $ git clone https://github.com/FeeiCN/autossh.git
    $ sudo cp autossh/autossh /usr/local/bin/
    

    autossh依赖expect,所以要先安装expect.

    $ cat ~/.autosshrc
    server_name|192.168.1.110|root|password|port|is_bastion
    

    demo:

    wufeifei|192.168.1.1|root|password|22|1
    

    用法

    ➜ autossh 1
    ############################################################
    #                     [AUTO SSH]                           #
    #                                                          #
    #                                                          #
    # [1] dev - 18.16.200.110:root                             #
    #                                                          #
    #                                                          #
    ############################################################
    spawn ssh -p22 -l root 18.16.200.110
    Last login: Mon Sep 21 23:55:59 2020 from 18.16.1.11
    [root@server110 ~]#
    

    islenbo版安装使用

    一键安装

    1. 下载与当前操作系统相匹配的压缩包并解压,运行install脚本,程序将自动安装至~/autossh目录,并在~/.bash_profile中更新PATH环境变量,使autossh能在任意目录生效。

    手动安装

    1. 下载与当前操作系统相匹配的压缩包,解压到自定义目录,Mac/Linux 用户推荐解压到 ~/autossh 目录。
    2. 修改环境变量,在PATH中添加 ~/autossh

    配置文件说明

    show_detail: bool <是否显示服务器详情(用户、IP)>
    options:
      ServerAliveInterval: int <是否定时发送心跳包,与SSH ServerAliveInterval属性用法相同>
    servers:
      - name: string <显示名称>
        ip: string <服务器IP>
        port: int <端口>
        user: string <用户名>
        password: string <密码>
        method: string <鉴权方式,password-密码 key-密钥>
        key: string <私钥路径>
        options:
          ServerAliveInterval: int <与根节点ServerAliveInterval用法相同,该值会覆盖根节点的值>
        alias: string <别名>
        log:
          enable: bool <是否启用日志>
          filename: string <日志路径, 如 /tmp/%n-%u-%dt.log 支持变量请参考下方《日志变量》章节>
          mode: string <遇到同名日志的处理模式,cover-覆盖 append-追加,默认为cover>
    groups:
      - group_name: string <组名>
        prefix: string <组前缀>
        servers: array <服务器列表,配置与servers相同,配置说明略>
        collapse: bool <是否折叠>
        proxy:
          type: string <代理方式,目前仅支持SOCKS5>
          server: string <代理服务器地址>
          port: int <端口号>
          user: string <用户,若无留空>
          password: string <密码,若无留空>
    

    日志变量

    变量 说明 示例
    %g 组名(group_name) MyGroup1
    %n 显示名称(name) vagrant
    %u 用户名(user) root
    %a 别名(alias) vagrant
    %dt 日期时间 20190821223010
    %d 日期 20190821

    常规用法

    将autossh放入PATH环境变量后,可在任意目录执行autossh命令,弹出菜单,输入相应的服务器编号或别名即可自动登录。

    指定配置文件

    autossh 默认读取同目录下的 config.json 文件,你也可以指定其他配置,使用 -c 或 -config 参数,如:

    autossh -c=file
    autossh -config=file
    

    快捷登录

    当你已经记住某一台服务器的编号或别名之后,可直接输入 autossh 编号/别名 实现快捷登录,如:

    autossh 1
    autossh vagrant
    

    cp 文件传输

    文件传输的用法类似scp,但使用的是sftp协议,支持 local <-> remote 和 remote <-> remote 传输。

    local -> remote

    # 1:/tmp/1.txt 表示config.json中编号为1的服务器的/tmp/1.txt文件
    autossh cp ./test.txt 1:/tmp/1.txt
    
    # vagrant 表示config.json中别名为vagrant的服务器
    autossh cp ./test.txt vagrant:/tmp/1.txt
    

    remote -> local

    autossh cp 1:/tmp/1.txt ./test.txt
    

    remote -> remote

    autossh cp 1:/tmp/1.txt 2:/tmp/1.txt
    

    多文件传输

    autossh cp ./1.txt ./2.txt 1:/tmp/
    autossh cp 1:/tmp/1.txt 1:/tmp/2.txt ./
    

    文件夹传输

    autossh cp -r ./dir 1:/tmp
    

    更新检测

    autossh upgrade
    

    参考

    FeeiCN/autossh

    islenbo/autossh

    Mac上使用Item2+lrzsz+autossh管理Linux服务器

    SSH 远程登录「记住密码」

    autossh反向代理实现内网穿透

    为 autoSSH 端口转发配置 systemd 守护进程

    AutoSSH 是一种用以对 SSH 登录进行安全地自动化的软件。!

    利用ssh反向穿透实现内网服务器自动部署

    centos下使用autossh命令

  • 相关阅读:
    mysql中事务隔离级别可重复读说明
    Zookeeper安装与启动
    PHP闭包之bind和bindTo
    使用WebPack打包
    用Python下载momentum中的精美壁纸
    supervisor使用
    Shell脚本:RedisKey批量删除
    使用Certbot配置站点的https
    PHPfmt代码格式化
    创建用私钥签名的证书
  • 原文地址:https://www.cnblogs.com/hongdada/p/13711688.html
Copyright © 2020-2023  润新知