<?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>Forem: NKN</title>
    <description>The latest articles on Forem by NKN (@nknorg).</description>
    <link>https://forem.com/nknorg</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%2Forganization%2Fprofile_image%2F2046%2F748f2fee-d427-48da-b5e8-5f95352b6270.png</url>
      <title>Forem: NKN</title>
      <link>https://forem.com/nknorg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nknorg"/>
    <language>en</language>
    <item>
      <title>Encrypted Stream for net.Conn or io.ReadWriter</title>
      <dc:creator>Zheng "Bruce" Li</dc:creator>
      <pubDate>Wed, 03 Jun 2020 20:41:10 +0000</pubDate>
      <link>https://forem.com/nknorg/encrypted-stream-for-net-conn-or-io-readwriter-3d44</link>
      <guid>https://forem.com/nknorg/encrypted-stream-for-net-conn-or-io-readwriter-3d44</guid>
      <description>&lt;p&gt;It's surprising to find that no Golang library can easily transform a &lt;code&gt;net.Conn&lt;/code&gt; to an encrypted and/or authenticated &lt;code&gt;net.Conn&lt;/code&gt;. So I wrote one that works in one line, welcome to give it a try!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nknorg/encrypted-stream"&gt;https://github.com/nknorg/encrypted-stream&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Encrypted-stream is a Golang library that transforms any &lt;code&gt;net.Conn&lt;/code&gt; or &lt;code&gt;io.ReadWriter&lt;/code&gt; stream to an encrypted and/or authenticated stream.&lt;/p&gt;

&lt;p&gt;The encrypted stream implements &lt;code&gt;net.Conn&lt;/code&gt; and &lt;code&gt;io.ReadWriter&lt;/code&gt; and can be used as drop-in replacement.&lt;/p&gt;

&lt;p&gt;Works with any encryption, authentication, or authenticated encryption algorithm or even arbitrary transformation. Only a cipher that implements encrypt/decrypt needs to be provided. XSalsa20-Poly1305 and AES-GCM are provided as reference cipher.&lt;/p&gt;

&lt;p&gt;The encrypted stream only adds a small constant memory overhead compared to the original stream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Assume you have a net.Conn and you want to transform it into an encrypted net.Conn:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;conn, err := net.Dial("tcp", "host:port")&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You first need to have a shared key at both side of the connection, (e.g. derived from key exchange algorithm, or pre-determined). Then all you need to do is to choose or implements a cipher:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;encryptedConn, err := stream.NewEncryptedStream(conn, &amp;amp;stream.Config{&lt;br&gt;
  Cipher: stream.NewXSalsa20Poly1305Cipher(&amp;amp;key),&lt;br&gt;
})&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Now you can use encryptedConn just like conn, but everything is encrypted and authenticated.&lt;/p&gt;

&lt;p&gt;See stream_test.go for complete example and benchmark with TCP connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmark
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go test -v -bench=. -run=^$
goos: darwin
goarch: amd64
pkg: github.com/nknorg/encrypted-stream
BenchmarkPipeXSalsa20Poly1305-12            4712        254008 ns/op     516.01 MB/s           1 B/op          0 allocs/op
BenchmarkPipeAESGCM128-12                  18675         65688 ns/op    1995.38 MB/s           0 B/op          0 allocs/op
BenchmarkPipeAESGCM256-12                  16060         74029 ns/op    1770.55 MB/s           0 B/op          0 allocs/op
BenchmarkTCPXSalsa20Poly1305-12             6760        263446 ns/op     497.53 MB/s           0 B/op          0 allocs/op
BenchmarkTCPAESGCM128-12                   14780         82979 ns/op    1579.57 MB/s           0 B/op          0 allocs/op
BenchmarkTCPAESGCM256-12                   13321         92393 ns/op    1418.64 MB/s           0 B/op          0 allocs/op
PASS
ok      github.com/nknorg/encrypted-stream  9.471s
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>go</category>
      <category>github</category>
      <category>encryption</category>
      <category>security</category>
    </item>
    <item>
      <title>NKN SDK: powering client side communication without servers</title>
      <dc:creator>Zheng "Bruce" Li</dc:creator>
      <pubDate>Wed, 25 Mar 2020 17:31:01 +0000</pubDate>
      <link>https://forem.com/nknorg/nkn-sdk-powering-client-side-communication-without-servers-4c7l</link>
      <guid>https://forem.com/nknorg/nkn-sdk-powering-client-side-communication-without-servers-4c7l</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CGnLcS4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.nkn.org/wp-content/uploads/2020/03/NKN-Github-scaled.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CGnLcS4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.nkn.org/wp-content/uploads/2020/03/NKN-Github-scaled.jpg" alt="NKN GitHub SDK"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What can developers do with NKN’s latest SDK, a decentralized communication stack that enables true peer to peer messaging, streaming, and file transfer? We would like to sort them into two main categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Things you can do &lt;strong&gt;&lt;span&gt;&lt;span&gt;ONLY&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt; with NKN SDK.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Send and receive data for free between any NKN powered apps regardless of their network condition without setting up a server or relying on any third party services.&lt;/li&gt;
&lt;li&gt;Network agnostic: Neither sender nor receiver needs to have public IP address or port forwarding. NKN powered apps only establish outbound (websocket) connections, so Internet access is all they need. This is ideal for client side peer to peer communication.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Things you can do &lt;strong&gt;&lt;span&gt;&lt;span&gt;BETTER&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt; with NKN SDK&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Top level security: All data are end to end authenticated and encrypted. No one else in the world except sender and receiver can see or modify the content of the data. The same public key is used for both routing and encryption, eliminating the possibility of man in the middle attack.&lt;/li&gt;
&lt;li&gt;Decent performance: By aggregating multiple overlay paths concurrently, NKN  powered apps can get ~100ms end to end latency and 10+mbps end to end session throughput between most international locations. This might sound modest, but it is actually faster than most file transfer services (e.g. instant messenger, gmail/google-drive, wetransfer.com, or dropbox)&lt;/li&gt;
&lt;li&gt;Everything is free, open source and decentralized.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NKN recently combined three Javascript SDKs (client, multi-client and wallet) into a single one, and added several important new features that developers will love. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://github.com/nknorg/nkn-sdk-js#client"&gt;NKN Client&lt;/a&gt;: Send and receive data for free between any NKN clients regardless their network condition without setting up a server or relying on any third party services. Data are end to end encrypted by default. Typically you might want to use &lt;a href="https://github.com/nknorg/nkn-sdk-js#multiclient"&gt;multiclient&lt;/a&gt; instead of using client directly.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://github.com/nknorg/nkn-sdk-js#multiclient"&gt;NKN MultiClient&lt;/a&gt;: Send and receive data using multiple NKN clients concurrently to improve reliability and latency. In addition, it supports session mode, a reliable streaming protocol similar to TCP based on &lt;a href="https://github.com/nknorg/ncp-js"&gt;ncp&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://github.com/nknorg/nkn-sdk-js#wallet"&gt;NKN Wallet&lt;/a&gt;: Wallet SDK for &lt;a href="https://github.com/nknorg/nkn"&gt;NKN blockchain&lt;/a&gt;. It can be used to create wallet, transfer token to NKN wallet address, register name, subscribe to topic, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Several example applications that are built on NKN SDK are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  nMobile: a secure mobile wallet and chat application.

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://nmobile.nkn.org"&gt;More information&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://play.google.com/store/apps/details?id=org.nkn.mobile.app"&gt;Google Play Store download&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;  D-Chat: a decentralized chat as Chrome/Firefox browser extension.

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://forum.nkn.org/t/d-chat/1036"&gt;More information&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://gitlab.com/losnappas/d-chat"&gt;Gitlab&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;  nFTP: a high throughput and direct file transfer between any clients

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://forum.nkn.org/t/nkn-d-ftp-high-throughput-file-transfer-using-nkn-client/1711"&gt;More information&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://nftp.nkn.org"&gt;Experience web app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://github.com/nknorg/nkn-file-transfer"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if your application needs these unique communication capabilities of NKN, would like to simplify and get rid of the servers, or simply to reduce server costs, you can head to NKN’s Developer Portal as well as our github repository to get started:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.nkn.org/developer/"&gt;https://www.nkn.org/developer/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nknorg/nkn-sdk-js"&gt;https://github.com/nknorg/nkn-sdk-js&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>webdev</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Secure Remote File Access for 
Network Attached Storage (NAS)</title>
      <dc:creator>Allen Dixon</dc:creator>
      <pubDate>Tue, 10 Mar 2020 22:20:50 +0000</pubDate>
      <link>https://forem.com/nknorg/secure-remote-file-access-for-network-attached-storage-nas-5fnd</link>
      <guid>https://forem.com/nknorg/secure-remote-file-access-for-network-attached-storage-nas-5fnd</guid>
      <description>&lt;p&gt;Network Attached Storage (NAS) have enjoyed wide adoption both at home and in enterprises, offering a more secure and lower cost local storage as an alternative or complement to cloud based storage. With NKN’s secure remote file access service, users can access their NAS files from anywhere without the need to host a central server, saving development and maintenance effort, as well as time and money. And users can enjoy even higher levels of security and privacy when accessing NAS remotely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Secure Access from Anywhere - Access your files securely from anywhere even if your NAS is behind a router/firewall with no public IP address or open ports, by using NKN’s unique NKN addressing and network architecture&lt;/li&gt;
&lt;li&gt;Reliable - NKN’s network of up to 20,000 servers in more than 40 countries ensures there is always a relay node available.&lt;/li&gt;
&lt;li&gt;One Connection - Access all the files and services on your NAS from one connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Solution Overview
&lt;/h3&gt;

&lt;p&gt;NKN secure remote file access service creates an end-to-end encrypted tunnel between the NAS device and the remote application.  In order to accomplish this, internet connections are established by both the NAS device and remote application to a series of relay nodes within NKN’s public server network.  Multiple nodes are used for both reliability as well as to enable faster transfer speed via multi-path data routing and aggregation .  These relay nodes provide the interconnect to establish a single virtual tunnel between the NAS device and remote application.  Relay nodes also provide a publicly available connection point for the NAS device, which are often connected behind a firewall or NAT gateway and do not have a public IP address or open ports.  Please see figure 1 below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zjt6Ji7T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9gamt88xn4qklx0pbnm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zjt6Ji7T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9gamt88xn4qklx0pbnm5.png" alt="Fig1: NKN Tunnel via multiple relay node&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once a connection between the NAS device and relay node is established it will begin listening on a unique NKN Address (For example: 20d72feef55…) as shown in Figure 2.  This is a routable address within the NKN network and will be used by the remote application to establish a connection to the same relay nodes as the NAS.  In addition, this NKN Address also includes a public key which will help establish E2E encryption without the need to consult a 3rd party Certificate Authority (CA). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XL_Jnzb5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y5zy2vk5ev83ka3hlxo5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XL_Jnzb5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y5zy2vk5ev83ka3hlxo5.png" alt="Figure 2: NKN Address used to establish E2E encryption&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the tunnel is established, the remote application will have access to any of the local services available on the NAS including access to the users content such as photos, movies, and other files. &lt;/p&gt;

&lt;p&gt;There are additional security measures that the NAS device can set up for even more protection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a whitelist of allowed user applications, as identified by user app’s NKN address&lt;/li&gt;
&lt;li&gt;Enforce user IAM (Identity and Access Management) roles and privileges to better manage file access rights in a finer grain&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;Typically for best user experience, NAS vendors work with NKN technical team to integrate NKN tunnel service with their NAS firmware and their mobile app. However, if you just want to try out NKN secure remote file access solution without commiting to integration, you can use the following steps to test it out.&lt;/p&gt;
&lt;h2&gt;
  
  
  Download the nkn-tunnel SDK
&lt;/h2&gt;

&lt;p&gt;In order to implement NKN’s secure remote file access solution, you must run nkn-tunnel as a standalone program or SDK on both the NAS device and remote application.&lt;/p&gt;

&lt;p&gt;Download the latest Mac, Windows, and Linux releases at:&lt;br&gt;
&lt;a href="https://github.com/nknorg/nkn-tunnel/releases"&gt;https://github.com/nknorg/nkn-tunnel/releases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE: nkn-tunnel is written in Go and can be compiled to work in your preferred environment such as &lt;a href="https://github.com/golang/go/wiki/Mobile"&gt;Android, iOS,&lt;/a&gt; and more.&lt;/p&gt;
&lt;h2&gt;
  
  
  Start nkn-tunnel service
&lt;/h2&gt;
&lt;h2&gt;
  
  
  NAS Setup
&lt;/h2&gt;

&lt;p&gt;To start nkn-tunnel on NAS (server side), you can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./nkn-tunnel -from nkn -to 127.0.0.1:8080 -s &amp;lt;seed&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The use of -s is optional, for example if you wish to recover a pre-existing encryption key (or seed, 64 digit HEX). Otherwise a new key will be generated if this option is not set.&lt;/p&gt;

&lt;p&gt;The nkn-tunnel application will connect to the nkn network and will begin listening for secure connections on port 8080.  The output will show an NKN specific listening-address (see example below) which will be used by the remote application to connect.&lt;/p&gt;

&lt;p&gt;Example Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2020/03/02 13:33:53 Listening at
5177bc471bed64cc98b8d39c1b465b5d316cb756c1eeeb99d6b13700d86809f9
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Remote Application Setup
&lt;/h2&gt;

&lt;p&gt;To start nkn-tunnel on the remote application (client side), you can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./nkn-tunnel -from 127.0.0.1:8081 -to &amp;lt;listening-address&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The listening-address is the unique NKN address that was displayed when launching nkn-tunnel on the NAS device.&lt;/p&gt;

&lt;p&gt;For more information on nkn-tunnnel and its usage, please visit our &lt;a href="https://github.com/nknorg/nkn-tunnel"&gt;github&lt;/a&gt; for the latest release notes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Success Stories
&lt;/h3&gt;

&lt;p&gt;NKN’s Secure Remote File Access service has been successfully integrated and available on our customer’s consumer product deployed to more than 15,000 customers worldwide.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;NKN’s Secure Remote File Access service for Network Attached Storage turns your local storage into a universally accessible global storage.  You can remotely connect to your NAS, even if your device is behind a firewall or gateway, with no public IP address or open ports, and our all of your data is accessed via end-to-end encrypted tunnel for security.  The service also offers accelerated performance for downloading data from your NAS with several times faster download experience compared to a cloud based solution.  It only takes a few steps to setup and configure and we offer a free open source SDK to get you started.&lt;/p&gt;

&lt;p&gt;You can also find more product information and web-based test drive at:&lt;br&gt;
&lt;a href="https://dataride.nkn.org/filetransfer/"&gt;https://dataride.nkn.org/filetransfer/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Universally accessible NAS, accelerated data transfer, and low cost to deploy…  Enhance your NAS product today with NKN!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0O0yZHGc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lzblgtpla1kbhopk19qg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0O0yZHGc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lzblgtpla1kbhopk19qg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Home: &lt;a href="https://nkn.org/"&gt;https://nkn.org/&lt;/a&gt; &lt;br&gt;
Email: &lt;a href="mailto:contact@nkn.org"&gt;contact@nkn.org&lt;/a&gt; &lt;br&gt;
Telegram: &lt;a href="https://t.me/nknorg"&gt;https://t.me/nknorg&lt;/a&gt;&lt;br&gt;
Twitter: &lt;a href="https://twitter.com/NKN_ORG"&gt;https://twitter.com/NKN_ORG&lt;/a&gt; &lt;br&gt;
Forum: &lt;a href="https://forum.nkn.org"&gt;https://forum.nkn.org&lt;/a&gt; &lt;br&gt;
Medium: &lt;a href="https://medium.com/nknetwork"&gt;https://medium.com/nknetwork&lt;/a&gt; &lt;br&gt;
Linkedin: &lt;a href="https://www.linkedin.com/company/nknetwork/"&gt;https://www.linkedin.com/company/nknetwork/&lt;/a&gt; &lt;br&gt;
Github: &lt;a href="https://github.com/nknorg"&gt;https://github.com/nknorg&lt;/a&gt; &lt;br&gt;
Discord: &lt;a href="https://discord.gg/yVCWmkC"&gt;https://discord.gg/yVCWmkC&lt;/a&gt;&lt;br&gt;
YouTube: &lt;a href="http://www.youtube.com/c/NKNORG"&gt;http://www.youtube.com/c/NKNORG&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>serverless</category>
      <category>linux</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Use nsh to Run Secure Remote Commands</title>
      <dc:creator>Yilun Zhang</dc:creator>
      <pubDate>Mon, 09 Mar 2020 23:18:07 +0000</pubDate>
      <link>https://forem.com/nknorg/use-nsh-to-run-secure-remote-commands-13j8</link>
      <guid>https://forem.com/nknorg/use-nsh-to-run-secure-remote-commands-13j8</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;It can often be difficult to manage multiple machines on a daily basis.  While Secure Shell (SSH) is a good choice for remote access, the protocol itself has some drawbacks in both convenience and security.&lt;/p&gt;

&lt;p&gt;For instance, remote machines need to have a public IP address and a forwarded port in order to access them, which exposes them to the internet, or at least a larger network. This is especially concerning if you use a password for authentication instead of a public and private key pair.  Furthermore, if you don’t know the remote machine’s public key in advance, you might be vulnerable to a "&lt;a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack"&gt;man-in-the-middle&lt;/a&gt;" attack. And many remote machines you want to access either don’t have public IP address, or they have a dynamic IP address you might not know. &lt;/p&gt;

&lt;p&gt;In addition, SSH requires one connection per remote session.  If a user needs to run a single command across hundreds or even thousands of machines, they must first establish a connection to each machine with a TCP handshake, which is less efficient. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://forum.nkn.org/t/nkn-shell-nsh-a-new-kind-of-remote-shell-that-is-more-secure-and-convenient-than-ssh/1719"&gt;NKN Shell&lt;/a&gt;, or nsh, is an alternative to SSH that provides a convenient and secure way to run remote commands. nsh takes advantage of &lt;a href="https://thedailychain.com/nkn-the-primer/"&gt;NKN’s global public network&lt;/a&gt;  which provides secure and decentralized data transmission.  The architecture uses unique addresses that contain a public key used for both routing and end-to-end encryption without any public key infrastructure (PKI). The network also does not require the remote server to have a public IP address. The remote server only needs to have Internet access and be able to establish outbound HTTP and websocket connections. As a result, your remote machines are not exposed to the open Internet.&lt;/p&gt;

&lt;p&gt;In this tutorial you will use the &lt;a href="https://github.com/nknorg/nkn-shell-daemon"&gt;NKN shell daemon&lt;/a&gt; and the &lt;a href="https://github.com/nknorg/nkn-shell-client-xterm"&gt;NKN Shell Client Xterm&lt;/a&gt; applications to execute commands on a remote machine.  To do so, you will install and configure the NKN Shell daemon on a remote machine with internet access, generate a key pair, and make your connection from a client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow this tutorial you will need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One Ubuntu 18.04 server set up by following &lt;a href="https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04"&gt;the Ubuntu 18.04 initial server setup guide&lt;/a&gt;, including a non-root &lt;code&gt;sudo&lt;/code&gt;-enabled user and a firewall.&lt;/li&gt;
&lt;li&gt;A Web browser installed on your local machine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 — Installing NKN Shell Daemon on a Remote Server
&lt;/h2&gt;

&lt;p&gt;First, install the NKN shell daemon (&lt;code&gt;nsd&lt;/code&gt;) on your server. This application will invoke &lt;a href="https://github.com/nknorg/nkn-multiclient-js"&gt;nkn-multiclient&lt;/a&gt;, which will connect to NKN's public network and obtain an address for routing.  The daemon will then listen for incoming shell commands from authenticated and whitelisted clients, execute those commands, and then send back results.&lt;/p&gt;

&lt;p&gt;Start by downloading the latest &lt;a href="https://github.com/nknorg/nkn-shell-daemon/releases"&gt;pre-built nshd binary from GitHub&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/nknorg/nkn-shell-daemon/releases/latest/download/linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Decompress the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar -zxvf linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then move the files into the &lt;code&gt;/usr/local/bin&lt;/code&gt; directory so they are available system wide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mv ./linux-amd64/* /usr/local/bin/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, you'll configure this to run as a daemon process using Systemd so that it will restart if the server is reset.&lt;/p&gt;

&lt;p&gt;Create a file called &lt;code&gt;nshd.service&lt;/code&gt; in &lt;code&gt;/etc/systemd/system&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/systemd/system/nshd.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add the following service definition to the file to configure the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=NKN Shell Daemon
After=network.target

[Service]
Type=simple
User=root
Group=root
Restart=always
ExecStart=/usr/local/bin/nshd

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Learn more about Systemd unit files in &lt;a href="https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files"&gt;Understanding Systemd Units and Unit Files&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Save the file and exit the editor. Then enable and start the &lt;code&gt;nshd&lt;/code&gt; service with the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl enable nshd.service
sudo systemctl start nshd.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Run the following command to ensure the service is active and started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl status nshd.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll see that the status is active:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;● nshd.service - NKN Shell Daemon
   Loaded: loaded (/etc/systemd/system/nshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-02-19 19:16:02 UTC; 7s ago
 Main PID: 3457 (nshd)
    Tasks: 10 (limit: 1152)
   CGroup: /system.slice/nshd.service
           └─3457 /usr/local/bin/nshd

Feb 19 19:16:02 your_hostname systemd[1]: Started NKN Shell Daemon.
Feb 19 19:16:03 your_hostname nshd[3457]: Create directory /etc/nshd/
Feb 19 19:16:03 your_hostname nshd[3457]: Create password and save to file /etc/nshd/wallet.pswd
Feb 19 19:16:03 your_hostname nshd[3457]: Create wallet and save to file /etc/nshd/wallet.json
Feb 19 19:16:03 your_hostname nshd[3457]: Create authorized pubkeys file /etc/nshd/authorized_pubkeys
Feb 19 19:16:03 your_hostname nshd[3457]: Listening at d46567b883a3070ee3fe879d9fa2d5dc55a95f79ff2797c42df36c6979e5c4Aba
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In order to connect to your server, you'll need to get its NKN address, which you can find in the output of the previous command. You can also run the following command to obtain the address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nshd addr
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll see your address appear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;e70ca28ede84fc0659f2869255e8a393aef35b4fa5a7e036f29127c7dba75383
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Take note of this address as you will need it to connect to your server.&lt;/p&gt;

&lt;p&gt;Now that the daemon is running and listening, you can configure the web-based client to talk to the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 — Configuring Permissions for NKN Shell Client
&lt;/h2&gt;

&lt;p&gt;You'll need a compatible client that can connect to the remote machine. In this tutorial you'll use NKN Shell Client Xterm, a web-based NKN shell client. There are a few different ways to run it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the hosted version at &lt;a href="https://nsh.nkn.org/"&gt;https://nsh.nkn.org/&lt;/a&gt;. Note that while this web page is hosted on a server, it’s actually a pure local web app that runs in your browser.&lt;/li&gt;
&lt;li&gt;Get the &lt;a href="https://github.com/nknorg/nkn-shell-client-xterm"&gt;source code&lt;/a&gt; and host it yourself.&lt;/li&gt;
&lt;li&gt;Use the &lt;a href="https://chrome.google.com/webstore/detail/nshell/jeiiodgaanmdeechnildbmhgpikbfokd?hl=en-US"&gt;nShell Chrome extension&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial you'll use the hosted version. On your local machine, open your web browser and navigate to &lt;a href="https://nsh.nkn.org"&gt;https://nsh.nkn.org&lt;/a&gt;. You'll see a welcome screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y4mFpL3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Rapdxlc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y4mFpL3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Rapdxlc.png" alt="The Shell Client"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Generate New Key Pair&lt;/strong&gt;. Your keys will be generated and displayed as shown in the following image:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mH-dd6FF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/REmjvUz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mH-dd6FF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/REmjvUz.png" alt="The generated key pair"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: When you generate a new key pair, you will see a &lt;strong&gt;Secret Seed&lt;/strong&gt;. Keep this secret seed secure and safe, just like you would with your SSH private key. Anyone who has this secret seed can use it to regenerate your public key and then run commands on your remote machines. Your browser will remember this seed, but you should copy it somewhere safe so you can use it again on a new machine.&lt;/p&gt;

&lt;p&gt;Save the &lt;strong&gt;Secret Seed&lt;/strong&gt; somewhere safe. You can use it later to regenerate your public key so you can connect from a different client machine.&lt;/p&gt;

&lt;p&gt;Since this is a new key pair, you must add the &lt;strong&gt;Public Key&lt;/strong&gt; to the file &lt;code&gt;/etc/nshd/authorized_pubkeys&lt;/code&gt; on your server. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/etc/nshd/authorized_pubkeys&lt;/code&gt; has a similar role as the  &lt;code&gt;~/authorized_keys&lt;/code&gt; file which controls which SSH public keys can log in. The &lt;code&gt;authorized_pubkeys&lt;/code&gt; file can specify which user is associated with a key.  For security purposes, you'll want to log in using a non-root user in this tutorial, so you'll associate the generated public key with your &lt;strong&gt;sammy&lt;/strong&gt; user you created in the Initial Server Setup guide in this article's prerequisite.&lt;/p&gt;

&lt;p&gt;To associate a user with the public key, you'll need to get the user id (UID) and group id (GID) of this user. Execute the following command on your server while logged in as the &lt;strong&gt;sammy&lt;/strong&gt; user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll see the UID and GID of the user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uid=1000(sammy) gid=1000(sammy) groups=1000(sammy),27(sudo)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now open the &lt;code&gt;authorized_pubkeys&lt;/code&gt; file in your editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/nshd/authorized_pubkeys
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add a single line containing the public key, uid, and gid, separated by spaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5d5367a5730427c205904a4457392051d2045dbce0186518fb6eb24dd9e41ba6 1000 1000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Save the file.&lt;/p&gt;

&lt;p&gt;Verify that the file contains the correct content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat /etc/nshd/authorized_pubkeys
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll see your key printed on the screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5d5367a5730427c205904a4457392051d2045dbce0186518fb6eb24dd9e41ba6 1000 1000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then restart the &lt;code&gt;nshd&lt;/code&gt; daemon to apply the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart nshd.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's test it out by connecting to the server and running a command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — Sending a Command to the remote machine and receive a response
&lt;/h2&gt;

&lt;p&gt;In NKN Shell Client, enter your remote &lt;code&gt;nshd&lt;/code&gt; address from Step 1, as well as an optional client identifier:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HxSLTOuP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NqwWTBa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HxSLTOuP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/NqwWTBa.png" alt="The nsh website with remote address filled in"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Connect&lt;/strong&gt; to initiate the connection.&lt;/p&gt;

&lt;p&gt;You'll be connected to your remote machine and shown a terminal prompt within the browser.  From here you can use it just like SSH. For example, execute the following command to switch to the &lt;code&gt;/etc/nshd&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/nshd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then list its contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll see the contents of the directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;authorized_pubkeys  wallet.json  wallet.pswd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can disconnect by typing &lt;code&gt;exit&lt;/code&gt;. When you need to reconnect, revisit the web interface and enter your connection details. If you generate a new key pair, you'll need to add the new public key to your server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you installed and configured nsh to securely and conveniently send commands to a remote machine.  nsh is a great way to access your remote machines when you need to quickly run a command to get the latest status of a service or peek at some configuration settings.  The application is based on NKN’s global public network, and it’s free to use so you can incorporate it into your own application or workflow today.&lt;/p&gt;

&lt;p&gt;You can also explore &lt;a href="https://github.com/nknorg/nkn-tunnel"&gt;nkn-tunnel&lt;/a&gt; which supports original SSH or any other TCP based applications.&lt;/p&gt;

&lt;p&gt;The post was initially posted on DigitalOcean's blog: &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-nsh-to-run-secure-remote-commands-on-ubuntu-18-04"&gt;How To Use nsh to Run Secure Remote Commands On Ubuntu 18.04&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>devops</category>
      <category>security</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
