编程笔记

lifelong learning & practice makes perfect

ssh-usage

连接

  • -i指定密钥

  • -o加option

    1
    2
    -o TCPKeepAlive=yes        //长连接
    -o ServerAliveInterval=30 //

端口转发

1
2
3
4
ssh -L local_port:localhost:remote_port -N -T user@server_address -p   server_ssh_port
如:
ssh -L 9999:localhost:8888 -N -T user_test@111.111.111.111 -p 22
将发送到本地端口9999的请求数据转发到111.111.111.111转发到8888端口

配置

  1. config文件配置: ~/.ssh/config

    1
    2
    3
    4
    5
    6
    7
    8
    #配置
    Host gitee.com
    HostName gitee.com
    IdentityFile xxx/xxx/_id_rsa
    PreferredAuthentications publickey
    User xxx
    TCPKeepAlive=yes
    ServerAliveInterval 60
  2. 配置服务端

  • 件位置,全局位置: /etc/ssh/sshd_config
  • 文件位置,termux: $PREFIX/etc/ssh/sshd_config
  • 配置:
    • PasswordAuthentication (密码验证) yes/no
    • 启用密钥验证
      • RSAAuthentication (rsa秘钥) yes/no
      • PubkeyAuthentication (公钥) yes/no
  1. 认证秘钥,将公钥写入该文件(authorized_keys),就可使用该公钥登陆
    • 位置: ~/.authorized_keys

工具

  • windows terminal

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    连接远程机器使用 ssh 配置
    {
    "guid": "{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}",
    "hidden": false,
    "name": "xxxxxxx",
    //密钥放在本地,-i 指定密钥位置
    "commandline": "ssh -i xxxxxxx_id_rsa user@host -p xxxxxxxx -o TCPKeepAlive=yes -o ServerAliveInterval=30",
    "startingDirectory": "/home/xxxxxxx",
    "icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png"
    }

欢迎关注我的其它发布渠道