工具癖程序员

map2cloud - 映射本地端口至云端

2017-09-13  本文已影响126人  smallmuou

2017.9.13
开源工具

很多时候,我们需要远程访问本地的服务,一般我们是借助于Teamviewer或者花生壳,而这往往需要人在电脑旁或者外网ip变化导致无法访问,还有一点,无法真正做到本地化操作,体验比较差;而借助该工具就可以直接将本地服务映射到云端,我们只需要访问云端对应端口就能访问本地服务。目前该工具已开源,大家可以访问此地址:https://github.com/smallmuou/map2cloud。欢迎star和fork,若在使用过程中有发现问题,欢迎提issue.

准备

在使用该工具,你至少需要准备一下几个内容

安装

1. 安装依赖工具 - autossh

可以使用yum或apt-get安装

# centos
yum install autossh

# debain
apt-get install autossh

如果以上方法无法安装,则请直接到autossh官网,下载源码并进行安装.

2. 安装map2cloud

sudo curl https://raw.githubusercontent.com/smallmuou/map2cloud/master/map2cloud > /usr/local/bin/map2cloud
sudo chmod +x /usr/local/bin/map2cloud

3. 生成rsa密钥

请使用ssh-keygen生成密钥对

ssh-keygen -t rsa

PS: 一路Enter就行,会在$Home/.ssh/下生成id_rsa和id_rsa.pub

4. 开启云端sshd的GatewayPorts功能

默认情况sshd是不开启GatewayPorts,这样无法外部访问.

vim /etc/ssh/sshd_config

GatewayPorts yes

保存退出后,重启sshd
service sshd restart

使用

USAGE: map2cloud [OPTIONS] ssh-user@cloud-ip [local-ip:]local-port cloud-port

DESCRIPTION:
    ssh-user        The ssh user to access to cloud server.
    cloud-ip        The cloud server ip or domain.
    local-ip        The local ip to map, default is localhost.
    local-port      The local port to map.
    cloud-port      The port which local port to map to. note it must be an even number.

OPTIONS:
    -h              Show this help message and exit.
    -i              Assign ssh private key path.
    -p              Assign ssh port.
    -n              Assign name of the service.

参数说明:

选项:

可以通过map2cloud -h查看详细的帮助

例子

map2cloud -i /root/.ssh/id_rsa -p 22 -n rssh root@your-cloud-ip 22 22222
/etc/init.d/rssh start

PS:这样我执行要执行ssh -p 22222 user@your-cloud-ip,就可以访问本地主机

map2cloud -n rhttp root@your-cloud-ip 192.168.12.100:80 10080
/etc/init.d/rhttp start

PS: 只需在浏览器下输入http://your-cloud-ip:10080,就可以访问本地服务

上一篇下一篇

猜你喜欢

热点阅读