2017-03-16 48 views
0

我想通过使用websockets并因此使用Web客户端来实现对位于NAT /防火墙(动态IP)后面的远程Raspberry的访问。远程SSH到NAT后面的Rasp通过网络

我想通过socket.io来做到这一点。 Raspbian和Web Client将订阅一个公共频道,然后他们将通过该频道交换ssh数据包。

难题在于将ssh数据包转换为Raspberry端的ssh命令。 有没有人实施过这个系统?

也许类似this

回答

0

如果你只是想避开使用ssh防火墙尝试tmate

下面是说明如何使用它进行远程设置

需要:

  • tmate
  • 一个谷歌帐户

`

#!/bin/bash 
#if Internet connection 
if [[ $(ping -W 1 -c 1 8.8.8.8) == *", 0% packet loss,"* ]]; 
then 
    echo online; 
    #if connection already exists 
    if [[ -S /tmp/tmate.sock ]]; 
    then 
     echo "aready up" 
    else 
     tmate -S /tmp/tmate.sock new-session -d 
    fi 
    tmate -S /tmp/tmate.sock wait tmate-ready 
    ssh=$(tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}') 
    ssh=$(sed 's~ssh ~~g' <<< $ssh) 
    echo $ssh 
    #sends ssh session to you 
    curl "https://script.google.com/macro/s/{{ google script location }}/exec?id={{ unique id for raspberry pi }}&ssh=$ssh" > /dev/null 
else 
    #no Internet retry in 30 seconds 
    echo offline; 
    sleep 30s 
    bash {{ location of this script }} 
fi 

对与@reboot {{ user }} bash {{ location of script }}

登录设置的用户cron作业的树莓派上面的代码谷歌和去http://script.google.com/当输入该代码

`

function doGet(e) { 
    var id = e.parameter.id; 
    var ssh = e.parameter.ssh; 
    var ss = SpreadsheetApp.openByUrl("{{ url of google spread sheet to dump data to }}").getActiveSheet(); 
    var lr = ss.getLastRow(); 
    var data = ss.getRange(1,1,lr,1).getValues(); 
    data = data.join("`").split("`"); 
    var loc = data.indexOf(id); 
    if(loc != -1){ 
    ss.getRange(loc+1,2).setValue(ssh); 
    }else{ 
    ss.appendRow([id,ssh]); 
    } 
} 

现在在发布命中部署的谷歌脚本作为Web应用程序甚至允许匿名,现在你有你的谷歌脚本网址。

注:

  • 任何与{{东西}}是你
  • 是输入端。如果树莓派会重新启动谷歌将覆盖与新

老SSH位置所有超越tmate的东西只是在失去电源或需要重启的情况下重新建立连接