How to Make Your Computer As a Remote Server

Preface

Recently, I'm working on a project related to self-driving system. I was assigned to a PC in the lab, however, I wish to remotely access to it at home. Thus I need to make the PC able to be SSHed from my own computer at home.

This article will briefly introduce you to the work flow of SSH and show an example of how to make SSH work on your computer so that you can remotely work at home.

What you need?

  • A Unix-based computer that will host the SSH server.
  • A different computer to test the remote connection to the server.
  • Access to a different network than the one to which your host machine is connected. (Optional but recommended: this is exactly what you want, right?)

Initial Setup

SSH stands for "secure socket shell", which will allow us to establish a secure connection between two computers, one serves as the server and the other is the client. The term "server" is often used a bit loosely, here we mean by the term is a process running on a computer that is tasked with managing access to a computer's resources over a network.

We will be installing the openssh-server application which will allow us to run an SSH server on our machine that will handle requests for access to the host computer from other devices.

Steps

Upgrade system packages and install openssh;

sudo apt-get upgrade
sudo apt-get install openssh-client
sudo apt-get install openssh-server

After installing those, check whether sshd is running on your machine:

ps -A | grep sshd

You should see something like:

16102 ?        00:00:00 sshd

You can also check whether you can login to the host machine from itself.

ssh localhost

If that succeeds, you can type exit to end the session.

Use ngrok to forward the port to a open server

  • Download ngrok from https://ngrok.com/download;
  • Connect your account after signing up: ./ngrok authtoken BUQXa2rWdvTmFJQDFRnm_7C9JRySLjr8eg7qgqKr9E
  • Start your tunnel: ./ngrok tcp 22;
  • You will see a window telling you which domain name and which port you should connect to;

Why Port Forwarding?

By doing all the steps above, you should be able to connect to your remote server successfully. But here comes the question: why do we need to use ngrok to access our remote server?

Network Address Translation (NAT) was created to allow a set of devices on a private network to share a single IP address. On the private network, each device receives its own private IP address. For example, the IP address you found above with ifconfig is the private IP address of your computer on your local network. Any time you access a webpage from one of the devices on your home network, the request is routed through an NAT device, which translates the private IP address into a request using the public IP address assigned to the router by your ISP. This is the address you will ultimately need to use when connecting from outside your local network.

Although NAT solves the device-limit problem, it adds a layer of complexity to setting up a home computer to accept SSH connections. When a client machine sends a request to connect to the public IP address, your router does not know which of the devices on your private network the request is sent to. There are two main solutions:

  • set up at the router to forward the port number 22 from the remote server to some port number in the router;
  • use ngrok to handle the request and sent back to the port 22 of the remote server;

Port forwarding means telling your router to forward requests made using a specific port to a particular device on your private network. It is then the responsibility of that device to handle the request. You may be wondering: why don't just send the request directly to the computer via the private IP address and avoid all of this port forwarding nonsense? Like the name implies, these IP addresses are private, so once you are on a different network, the internet-at-large has no knowledge of this private IP address and therefore the request to connect will fail.

External Resources

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,123评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,031评论 2 384
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,723评论 0 345
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,357评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,412评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,760评论 1 289
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,904评论 3 405
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,672评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,118评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,456评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,599评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,264评论 4 328
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,857评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,731评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,956评论 1 264
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,286评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,465评论 2 348

推荐阅读更多精彩内容