Learn Some Linux Series - Files over Shell, the Midnight Commander Basics

In this tutorial, we will talk about a simple TUI based program over terminal for files transfer not only locally on the same machine, but also, over VPN links between all of our devices.

Why TUI (text user interface) based program for file transfer over normal SCP/SFTP or just cp command? Simple reason would be speed and presentation of all files in front of you, just like a windows explorer will do, but for both source and target sides. And we can use mouse to click/double click, keyboard arrows and keys, function keys to accomplish things like copy / delete / make a new directory, select and then quick view text files as per simple function keys menu shown at the bottom of the screen. We can either press Fn followed by corresponding Fn key at the top of keyboard or Esc, followed by the number shown at the function key menu at the bottom (press ESC key, let it go and then press the number).

Midnight Commander (mc) uses FISH, a Files transfer over Shell protocol. If we simply needed an ultra light weight setup for our devices or on the go laptop to copy to or from, a shared location (like samba mounted network drive or USB stick), this is very convenient and extreme light weight way to achieve that, over bulky cloud based solutions.

Once installed, we see a beautiful GUI like screen for Linux and windows devices, which is mostly intuitive to follow. The look and feel is the same between windows and Linux and I see that you can also install it on Android. There are left and right arrows at the very top left and very top right below the menu bar) to navigate up and around the file system. We can do also click on the ^ that you will find towards right end of left or right side files panel, to go to the History to get to the file paths quickly. This history caret is also available at bottom for command prompt.

By default, we will just see the two panes that list files in the home directory. We can make either of left or right panel for our remote machine file system, by mouse clicking on Left or Right Menu at top and then selecting Shell Link. A small window opens and you type in there IP address or FQDN or short NetBIOS name (if you have added the names to IP mapping in the hosts file in each machine or you are behind the same home router) like ubuntu@10.8.0.3 and corresponding pane will show the home directory of the ubuntu user at remote machine.

Under the two panes, we will see a mc prompt, wherein we can type something like cd /path/to/directory and pane will accordingly go to that directory and list its files etc. We can then copy / paste or do other operations on the files in any directory that we can browse to.

Being a TUI based, it is difficult to explain here all the steps and options, but you may want to give it a try and it is very self explanatory. You may want to go to ESC 1 to see built-in help that explains most of these things. To remove any overlay screen / dialog box, press ESC couple of times.

Normally, we need to click on a menu or file to highlight it and then we can use arrow keys to further navigate around. If you don’t have a mouse attached, you can press ESC 9 and you will find that you can now use keyboard arrow keys to move across top menu bar and pull down menus etc.

If you do have mouse attached, mouse clicks are much faster.

Pressing Ctrl plus O (this is O and not zero), we can toggle back and forth between MC menu and our shell terminal.

Install is simple in just a few steps:

On debian based devices, including RPi

sudo apt install mc

To launch the app, type mc on the terminal.

For Windows 7, 10 and 11, you can download from link below.

https://sourceforge.net/projects/mcwin32/files/latest/download

To launch the app on windows, find the GNU Midnight Commander from search box.

In Windows mc, at command prompt at bottom, after we select a file in left or right panel, to let mc know which machine / directory we are working on, type cd followed with windows styled path, like C:\Windows\ and hit enter and panel will change to that directory. Of course, mouse clicks can also be used.

Note prompt at bottom can only be used for local filesystem navigation.

To get to a remote machines, we will go to Left or Right Menu at top, and then select SFTP and it will open a window asking to type in host,

we will type in there

sftp ubuntu@AWSPublicIP:55222

Skip the :port if it is default SSH TCP/22.

and hit enter. We will be prompted to accept the cert / SSH fingerprint of the remote server. Press ESC to remove the information window and then type in password (since we have not set up key based authentication yet). This signature of remote machine will be stored in mc database for future.

One of the pane now will show file system from remote machine and we can do file transfer between local and remote machine.

We need to use ssh agent for copy the local generated RSA Key so that it can be used by mc when doing SSH or SFTP to the remote machine. Follow Tutorial Part 1 on AWS, OpenVPN and Nomachine to generate and upload to the server or other machines. Then do the following:


This will copy the key available at default location to the ssh agent. We can read more about SSH agent a link below:

ssh.com

Ssh-agent single sign-on configuration, agent forwarding, the agent protocol.

Ssh-agent single sign-on configuration, agent forwarding, the agent protocol.

Now, we can go to Left or Right menu at top and then go to SFTP and type in remote server address as explained above and this time, it should not ask for password.

As a beginners, we will not need more functionality of mc, but please feel free to explore further.