Skip to content

Instantly share code, notes, and snippets.

@hunterhug
Last active October 11, 2017 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hunterhug/9a9874118f9a7ad38682b64581086006 to your computer and use it in GitHub Desktop.
Save hunterhug/9a9874118f9a7ad38682b64581086006 to your computer and use it in GitHub Desktop.
linux operation

SSH高级功能

代理

ssh -ND 1082 ubuntu@1.1.1.1

在本地开一个1082端口,做动态转发,暴露为socks5协议。程序需要明确生命使用该代理。比如 proxychains4google ext SwitchyOmega

这时可以使用sock5 127.0.0.1 1082代理, 所有经过此代理的TCP请求会经远程主机转发...

双重转发:

viaproxy 'socks5 127.0.0.1 1082' ssh -ND 1081 ubuntu@2.2.2.2

viaproxy参考:

#!/bin/bash
# Author: wonderbeyond@gmail.com
# Usage: viaproxy "socks5 127.0.0.1 1080" telnet some-host

command -v proxychains4 && proxychains=proxychains4 || proxychains=proxychains

proxy="$1"
shift

$proxychains -f <(/bin/echo -e "strict_chain\nproxy_dns\nlocalnet 127.0.0.0/255.0.0.0\n[ProxyList]\n$proxy") "$@"

https://gist.github.com/wonderbeyond/6ef3cdc191490e02a6b12162deab4fd7

隧道

本地是host1:

情形一: host1和host3互通,host3和host2互通, host1和host2不通, 需要host3做接力让host1访问host2

# 本地端口转发

ssh -NL 5556:host2:5555 ubuntu@host3 # 本地端口转发, 开一个5556端口,以目标服务器身份访问指定IP的指定端口。所有经过本地5556的数据都会由host3转到host2的555端口

ssh -NL 9901:host2:22 ubuntu@host3 
ssh -p 9901 localhost  # host1只要登录本地9901就可以通过host3登录host2

情形二: host3能访问host1, 但host1不能访问host3, host3和host2互通, host1和host2不通, 需要host3做接力让host1访问host2,此时本地端口转发失效

# 远程端口转发
# 在host3起命令, 登录host1, 让host1监听2121端口
ssh -R 2121:host2:21 host1

# 在host1经2121传数据, 会被host3收到并送到host2
ftp localhost:2121

终端GUI:terminator 终端复用:tmux -> byobu

@hunterhug
Copy link
Author

@hunterhug
Copy link
Author

proxy "socks5 127.0.0.1 9888" curl www.google.com

@hunterhug
Copy link
Author

viaproxy "socks5 127.0.0.1 9888" curl www.google.com

@hunterhug
Copy link
Author

ssh -ND 0.0.0.0:1082 ubuntu@1.1.1.1

@hunterhug
Copy link
Author

在阿里云启动命令 :

ssh -ND 9888 ubuntu@国外机器

config.json

{
    "server": ["阿里云IP"],
    "server_port": 443,
    "local_address": "127.0.0.1",
    "local_port": 1080,
    "password": "FFFFVVVCCCCKKKK",
    "timeout": 300,
    "method":"aes-128-cfb",
    "fast_open": true
}

proxy "socks5 127.0.0.1 9998" ssserver --config config.json

本地启动:

sslocal --config config.json

@hunterhug
Copy link
Author

proxy "socks5 127.0.0.1 9998" ssserver -c conf.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment