<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zhang Handuo</title>
    <description>The latest articles on DEV Community by Zhang Handuo (@zhanghanduo).</description>
    <link>https://dev.to/zhanghanduo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F101252%2Fc7faa8be-2f90-4cbf-ae44-2174d4215680.jpeg</url>
      <title>DEV Community: Zhang Handuo</title>
      <link>https://dev.to/zhanghanduo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zhanghanduo"/>
    <language>en</language>
    <item>
      <title>Remotely edit your work without using vim</title>
      <dc:creator>Zhang Handuo</dc:creator>
      <pubDate>Tue, 09 Apr 2019 08:52:10 +0000</pubDate>
      <link>https://dev.to/zhanghanduo/remotely-edit-your-work-without-using-vim-20pi</link>
      <guid>https://dev.to/zhanghanduo/remotely-edit-your-work-without-using-vim-20pi</guid>
      <description>&lt;p&gt;Remotely editing your work when your server does not have public IP address and you don't want to spend any money is not so easy. Maybe you can use Team viewer or Anydesk or even chrome remote desktop, but there are high latencies. Maybe you can use ngrok to remotely ssh to your remote server, but you have to use vim and you are not familiar with it at all 😧. I tried to use rmate but it is not convinient to edit across different files in a folder.&lt;/p&gt;

&lt;p&gt;I recently found an hot github repository called &lt;a href="https://github.com/codercom/code-server" rel="noopener noreferrer"&gt;code-server&lt;/a&gt; which is able to run &lt;strong&gt;VS Code&lt;/strong&gt; on a remote server, accessible through the browser. So it suddenly came to my mind that I can remotely edit any code for free as long as I have a linux/macOS environment. &lt;/p&gt;

&lt;p&gt;Let's consider you understand the basic knowledge of SSH key as you are going to use it. For tutorial about how to generate SSH keys, please refer to &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2" rel="noopener noreferrer"&gt;How to set up SSH keys&lt;/a&gt; and &lt;a href="https://help.github.com/en/articles/connecting-to-github-with-ssh" rel="noopener noreferrer"&gt;connecting to GitHub with SSH&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Firstly you need to see whether your server has a public IP address. If yes (I know this is not common), then things are really easy and you can just follow step 1, 2 and 3; otherwise, directly go to step 0, then step 2 and 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1. SSH connect
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh server_username@IP_address -L 8843:localhost:8843
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-L 8843:localhost:8843&lt;/code&gt; here is &lt;strong&gt;local port forwarding&lt;/strong&gt; which allows you to access local network resources that aren't exposed to the Internet. The first 8843 is local port, &lt;code&gt;localhost:8843&lt;/code&gt; is the remote &lt;strong&gt;code-server&lt;/strong&gt; default port.&lt;/p&gt;

&lt;p&gt;To see whether you can successfully links to the server. The prerequisites are 1) you installed openssh-client 2) you have generated SSH key. If not successfully, maybe you don't have a public IP address. Then go to step 0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2. Download code-server
&lt;/h2&gt;

&lt;p&gt;Open this page on your client browser, find the latest release of &lt;a href="https://github.com/codercom/code-server/releases" rel="noopener noreferrer"&gt;code-server&lt;/a&gt;. Find the binary file for linux and get the downloading address. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnfekp57y05t3q0xts01i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnfekp57y05t3q0xts01i.png" alt="Download binary file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then in the terminal window ssh connected to the remote server, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget code-server_downloading_address
# Example:
wget https://github.com/codercom/code-server/releases/download/1.696-vsc1.33.0/code-server1.696-vsc1.33.0-linux-x64.tar.gz
tar -xvzf code-server1.696-vsc1.33.0-linux-x64.tar.gz
cd code-server1.696-vsc1.33.0-linux-x64/
sudo mv code-server /usr/local/bin/
sudo chmod a+x /usr/local/bin/code-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then your &lt;strong&gt;code-server&lt;/strong&gt; will be installed!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3. Running code-server
&lt;/h2&gt;

&lt;p&gt;Go to the folder of your code waiting to be edited and type &lt;code&gt;code-server&lt;/code&gt; in the terminal window ssh connected to remote server.&lt;br&gt;
Then open your browser and type &lt;code&gt;localhost:8843&lt;/code&gt;, your workspace of VSCode will be revealed to you! The speed is satisfactory to me.&lt;/p&gt;


&lt;h2&gt;
  
  
  Step 0. Ngrok
&lt;/h2&gt;

&lt;p&gt;Some people will use VPS servers or cloud hosting providers like &lt;a href="//www.vultr.com"&gt;Vultr&lt;/a&gt;, AWS and so on to pay for a public IP address. But here we just need &lt;a href="//www.ngrok.com"&gt;Ngrok&lt;/a&gt;, a great tool that can create a tunnel from the public Internet to a port on your local machine. You can give this URL to anyone and any place without the need to pay any money!&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="//www.ngrok.com"&gt;Ngrok&lt;/a&gt; and sign up to get your authtoken. Follow the "Setup &amp;amp; Installation" and download ngrok onto your remote server (I suggest you read the &lt;a href="https://ngrok.com/docs" rel="noopener noreferrer"&gt;doc&lt;/a&gt; and check "ngrok configuration file" section) and throw the binary file into /usr/local/bin/. Maybe need to &lt;code&gt;sudo chmod a+x ngrok&lt;/code&gt;.&lt;br&gt;
Then type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ngrok tcp 22 --region ap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where --region refers to your region. There are four region options: us(Ohio), eu(Frankfurt), ap(Singapore), au(Sydney). If you don't select a region, the default one is us, which might be slow if you are not in the US.&lt;/p&gt;

&lt;p&gt;Then your screen will show something like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fik6nyv7vf0c1e76r80r3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fik6nyv7vf0c1e76r80r3.png" alt="ngrok"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is a number after &lt;code&gt;0.tcp.ngrok.io:&lt;/code&gt; &lt;strong&gt;15707&lt;/strong&gt;. You need to remember this port number. Please keep this window on if you want to keep this tunnel open.&lt;/p&gt;

&lt;p&gt;Then you can ssh to your remote server by copying the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh hd@0.tcp.ngrok.io -p15707 -L 8443:localhost:8443
#Or your region is ap
ssh hd@0.tcp.ap.ngrok.io -p15707 -L 8443:localhost:8443
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tool</category>
      <category>remote</category>
      <category>ngrok</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
