<?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: TJ Kolleh</title>
    <description>The latest articles on DEV Community by TJ Kolleh (@tkolleh).</description>
    <link>https://dev.to/tkolleh</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%2F216670%2F9dad0b4a-cc22-40ed-a519-d4e4a3efa3c1.jpeg</url>
      <title>DEV Community: TJ Kolleh</title>
      <link>https://dev.to/tkolleh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tkolleh"/>
    <language>en</language>
    <item>
      <title>Use local dev tools on remote files with SSHFS</title>
      <dc:creator>TJ Kolleh</dc:creator>
      <pubDate>Sat, 14 Nov 2020 03:31:22 +0000</pubDate>
      <link>https://dev.to/tkolleh/use-local-dev-tools-on-remote-files-with-sshfs-2ic6</link>
      <guid>https://dev.to/tkolleh/use-local-dev-tools-on-remote-files-with-sshfs-2ic6</guid>
      <description>&lt;p&gt;I often have to work with virtual machines or remote hosts. To utilize my local development environment while doing so I configure SSH and SSHFS. Enabling the use of tools on the local host while working with files on the remote, with the security of ssh.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSHFS&lt;/strong&gt; (SSH filesystem) enables the mounting of a remote directory over a normal ssh connection to the local filesystem. Prior to installing, make sure &lt;a href="https://dev.to/posts/ssh-ubuntu-virtualbox/post"&gt;SSH is setup&lt;/a&gt; with the appropriate keys.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download &amp;amp; Install &lt;a href="https://osxfuse.github.io/"&gt;FUSE for macOS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Download &amp;amp; Install &lt;a href="https://osxfuse.github.io/"&gt;SSHFS&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Mount remote filesystems
&lt;/h2&gt;

&lt;p&gt;The following command mounts the remote directory to a specified mount point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sshfs username@remotesystem:/remote/path/to/directory ~/mount/point
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://github.com/tkolleh/dotfiles/blob/master/ws/usrBinScripts/executable_rmount.sh"&gt;&lt;code&gt;rmount&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://github.com/tkolleh/dotfiles/blob/master/ws/usrBinScripts/executable_rumount.sh"&gt;&lt;code&gt;rumount&lt;/code&gt;&lt;/a&gt; bash scripts facilitate convenient mount and unmounts using &lt;code&gt;sshfs&lt;/code&gt;. To begin using the scripts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a folder named &lt;strong&gt;mounts&lt;/strong&gt; in your user home directory, &lt;code&gt;~/mounts&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Download the scripts and make them executable, &lt;code&gt;chmod u+x &amp;lt;path-to-script&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The functions reference host named in the local &lt;code&gt;~/.ssh/config&lt;/code&gt; file, configured with a key pair (without a password). See &lt;a href="https://dev.to/posts/ssh-ubuntu-virtualbox/post"&gt;earlier blog&lt;/a&gt; post on the subject for reference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;Host&lt;/span&gt; &lt;span class="n"&gt;ml&lt;/span&gt;
  &lt;span class="n"&gt;HostName&lt;/span&gt; &lt;span class="n"&gt;ec2&lt;/span&gt;&lt;span class="o"&gt;-*&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compute&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amazonaws&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
  &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="n"&gt;ubuntu&lt;/span&gt;
  &lt;span class="n"&gt;PreferredAuthentications&lt;/span&gt; &lt;span class="n"&gt;publickey&lt;/span&gt;
  &lt;span class="n"&gt;IdentitiesOnly&lt;/span&gt; &lt;span class="n"&gt;yes&lt;/span&gt;
  &lt;span class="n"&gt;IdentityFile&lt;/span&gt; &lt;span class="o"&gt;~/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;aws&lt;/span&gt;
  &lt;span class="n"&gt;Port&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Executing &lt;code&gt;rmount ml&lt;/code&gt; - will mount the entire filesystem to a local &lt;code&gt;ml&lt;/code&gt; (&lt;code&gt;~/mounts/ml&lt;/code&gt;) folder. A folder created by the function. The default "mounts" path, created earlier, can be changed by modifying the function. Executing &lt;code&gt;rmount ml:/home/ec2-user&lt;/code&gt; mounts the &lt;code&gt;ec2-user&lt;/code&gt; directory in &lt;code&gt;~/mounts/ml/&lt;/code&gt;. Running &lt;code&gt;rumount ml&lt;/code&gt;, removes the &lt;code&gt;ml&lt;/code&gt; folder and unmounts the remote filesystem. &lt;/p&gt;

&lt;p&gt;With a remote filesystem mounted locally, local development tools can be used without having to download each file or having to remember to sync files. Its a secure tunnel to your remote filesystem where files behave almost as if they're local.&lt;/p&gt;



&lt;p&gt;I'm publishing this as part of 100 Days To Offload. You can learn more by visiting &lt;a href="https://100daystooffload.com"&gt;#100DaysToOffload&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://curiousstemlovingfellow.com/posts/sshfs-ubuntu-virtualbox/post/"&gt;Original post...&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terminal</category>
      <category>ssh</category>
      <category>shell</category>
      <category>virtualmachine</category>
    </item>
    <item>
      <title>SSH To Guest or Remote OS</title>
      <dc:creator>TJ Kolleh</dc:creator>
      <pubDate>Wed, 22 Apr 2020 17:17:10 +0000</pubDate>
      <link>https://dev.to/tkolleh/ssh-to-guest-or-remote-os-8ch</link>
      <guid>https://dev.to/tkolleh/ssh-to-guest-or-remote-os-8ch</guid>
      <description>&lt;p&gt;I often have to work with virtual machines and/or remote servers. When its more convenient to use local developer tools, I rely on SSH and SSHFS. This post describes how to setup SSH to connect to a Ubuntu VirtualBox VM. The information can also be applied to other remotes hosts. Connecting to a remote OS via SSH is the first step in extending the use of your local tools for remote development. A subsequent blog post describes how to configure SSHFS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;



&lt;ul&gt;
&lt;li&gt;Setup Virtual Box&lt;/li&gt;
&lt;li&gt;Communicate with the guest OS (SSH)&lt;/li&gt;
&lt;li&gt;Login with SSH keys&lt;/li&gt;
&lt;/ul&gt;



&lt;h3&gt;
  
  
  Setup Virtual Box
&lt;/h3&gt;

&lt;p&gt;Download and install &lt;a href="https://www.virtualbox.org/wiki/Downloads"&gt;VirtualBox&lt;/a&gt; to the host operating system (host OS). Create or import a new virtual machine with your preferred OS. For this post, Ubuntu OS (guest OS) will be running inside of Oracle VirtualBox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tiZyVEWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://curiousstemlovingfellow-blog-data.s3.amazonaws.com/blog-posts/manager-window-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tiZyVEWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://curiousstemlovingfellow-blog-data.s3.amazonaws.com/blog-posts/manager-window-1.png" alt="VirtualBox Manager Window with VMs" width="880" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Communicate with the guest OS (SSH)
&lt;/h3&gt;

&lt;p&gt;SSH provides secure login to remote machines over a network, and &lt;a href="https://en.wikipedia.org/wiki/Secure_Shell#Uses"&gt;more&lt;/a&gt;. From the VirtualBox Manager start the Ubuntu VM (graphically) and open the terminal application in Ubuntu. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install the OpenSSH daemon/server (sshd)&lt;/strong&gt; with the command &lt;code&gt;sudo apt-get install openssh-server&lt;/code&gt;. Then run the following commands to - enable SSH, &lt;strong&gt;start the SSH daemon&lt;/strong&gt;, and check it's status. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check the Ubuntu OS version per the output of the &lt;code&gt;cat /etc/*release*&lt;/code&gt; command.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  Ubuntu version 16.04 LTS or newer
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;sudo systemctl enable ssh&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sudo systemctl start ssh&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sudo systemctl status ssh&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Ubuntu versions 14.04.4 LTS
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;sudo service ssh start&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sudo service ssh status&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Allow SSH through &lt;strong&gt;the Ubuntu firewall (ufw)&lt;/strong&gt;, if active. Check firewall status with the command &lt;code&gt;sudo ufw status&lt;/code&gt;. Allow SSH through the firewall (port 22) using the command &lt;code&gt;sudo ufw allow ssh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To find the guest OS on the network we can use its IP address or use port forwarding to send all traffic from host to guest via a designated port.&lt;/p&gt;

&lt;h5&gt;
  
  
  Connect via port forwarding
&lt;/h5&gt;

&lt;p&gt;Select &lt;em&gt;settings&lt;/em&gt; from the VirtualBox manager then &lt;em&gt;network -&amp;gt; advanced -&amp;gt; port forwarding&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kr2Pe1RV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://curiousstemlovingfellow-blog-data.s3.amazonaws.com/blog-posts/manager-window-settings.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kr2Pe1RV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://curiousstemlovingfellow-blog-data.s3.amazonaws.com/blog-posts/manager-window-settings.png" alt="Settings window for port forwarding" width="880" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add a new port forwarding rule that maps host OS port 2222 to guest OS port 22 such that;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protocol: TCP&lt;/li&gt;
&lt;li&gt;Host IP: 127.0.0.1&lt;/li&gt;
&lt;li&gt;Host Port: 2222&lt;/li&gt;
&lt;li&gt;Guest IP: &lt;em&gt;N/A (empty)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Guest Port: 22&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T66mqxdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://curiousstemlovingfellow-blog-data.s3.amazonaws.com/blog-posts/manager-window-settings-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T66mqxdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://curiousstemlovingfellow-blog-data.s3.amazonaws.com/blog-posts/manager-window-settings-2.png" alt="Port forwarding rules window" width="880" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the host OS - open a terminal/command prompt window and &lt;strong&gt;SSH to the guest OS&lt;/strong&gt;;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ssh&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="mi"&gt;2222&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Connect via IP address (optional)
&lt;/h5&gt;

&lt;p&gt;If port forwarding doesn't work or you prefer to connect via IP address, find the guest OS IP from the output of the &lt;code&gt;ifconfig&lt;/code&gt; command. Open the &lt;em&gt;settings&lt;/em&gt; window, shown above, select &lt;em&gt;network -&amp;gt; attached to -&amp;gt; host-only adapter&lt;/em&gt; save selection. Using the guest OS IP address, create a SSH connection;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ssh&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Login with SSH keys
&lt;/h3&gt;

&lt;p&gt;Copy your public key to the guest/remote host using &lt;code&gt;ssh-copy-id&lt;/code&gt;. See references for generating a &lt;a href="https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key"&gt;RSA key pair&lt;/a&gt;. To facilitate the use of scripts, don't include a passphrase while generating keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;~/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pub&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example command for a guest OS running in VirtualBox:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;ubuntu&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;~/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gen&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;nopass_ras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pub&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="mi"&gt;2222&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User authorization with RSA public key has been achieved. The command &lt;code&gt;ssh ubuntu@localhost -p 2222&lt;/code&gt; no longer prompts for a password.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tools.ietf.org/html/rfc4251"&gt;The Secure Shell Protocol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kb.iu.edu/d/aelc"&gt;SSH and SSH2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.ubuntu18.com/install-openssh-ubuntu-18/"&gt;Ubuntu 18&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

</description>
    </item>
  </channel>
</rss>
