- Pip install Boto3 - Thu, Mar 24 2022
- Install Boto3 (AWS SDK for Python) in Visual Studio Code (VS Code) on Windows - Wed, Feb 23 2022
- Automatically mount an NVMe EBS volume in an EC2 Linux instance using fstab - Mon, Feb 21 2022
Why use Midnight Commander for remote file transfers ^
Midnight Commander is one of the first tools I install on every Linux box. The nice thing about this file manager is that it allows you to connect remotely via SSH and SFTP easily to copy, move, view, or edit files on the remote machine.
Midnight Commander is a clone of Norton Commander, a file manager for MS-DOS that I have been using since long before Windows existed. Midnight Commander has an almost identical user interface because there was really not much to improve about Norton Commander.
If you are a Linux admin, you are used to working on a command line and might wonder why you would need a file manager with a GUI. While it is certainly a matter of taste, it is also often a matter of speed.
Copying or moving files with Midnight Commander is usually faster than the CLI if you have to skim a large number of files to decide which files you want to copy. My guess is that the tool's name stems from the fact that you can use it in the middle of the night without worrying about moving the wrong files due to a lack of concentration. In Midnight Commander, you can just select each file with CTRL+T and then copy or move it.
Another very useful feature is that if you want to view the contents of a file, you can simply hit F3. The file manager also allows you to remotely edit files using nano.
Because you can run Midnight Commander in a SSH terminal window, you can work with it on any Linux machine without a desktop environment, such as GNOME or KDE.
If you have to copy files to another server, you don't have to install anything on the remote system. On your local system, you just have to install Midnight Commander once with a simple one-liner (for instance, on Ubuntu):
sudo apt install mc
Files transferred over shell protocol (FISH) ^
When transferring files via SSH in Midnight Commander, you have to keep in mind that Midnight Commander uses FISH for remote shell connections, which does not require SCP to be installed on the remote system.
The main advantage over SCP on the command line is that you can also list the contents of the remote system, and the advantage over SFTP is that you don't have leave your shell and work on the SFTP console.
Connect to the remote host with SSH in Midnight Commander ^
I hope you have disabled password authentication for SSH on all your Linux machines. Just in case you are still working with passwords, you can simply connect to the remote system by clicking the Left or Right menu or, alternatively, pressing F9+L (or F9+R) and then selecting Shell link.
Then, as in SSH or SCP, you can connect to the remote system with this syntax:
Midnight Commander will then ask for the user password.
Configuring Shell link in Midnight Commander for public key authentication ^
In Midnight Commander, unlike in SSH or SCP, you cannot pass the identity file with the -i parameter for public key authentication. Thus, you have to store the SSH configuration in your config file. The file is located in your home directory in ~/.ssh/config.
If the file does not exist, you can just edit with the nano editor and then make sure that only your user has access to it:
chmod 600 config
The config file should contain the location of your private SSH key, the corresponding username, and the hostname. In addition, you can configure the port and the alias you want to use to save some typing (Host command).
Host yourHost HostName 10.0.0.1 Port 2222 User ubuntu IdentityFile ~/.ssh/privatekey.key
In Midnight Commander, you then simply enter your alias after you select Shell link.
If you connect the first time to the remote host, you will have to confirm its authenticity.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
If you prefer typing over clicking, you can connect to your remote host with this command:
Midnight Commander and SFTP link ^
You can also transfer files via SFTP in Midnight Commander. If you work on the command line, it makes a difference if you work with SCP or SFTP. With SCP, you can't list the contents of a directory; with SFTP, you have to use the old FTP console with its commands. Because you work in a GUI in Midnight Commander, it does not really make a difference which protocol you use.
However, it appears the SFTP implementation in Midnight Commander has a bug that has never been fixed. The SFTP link command ignores the SSH config file. This means you can't use public key authentication. Instead, you have to work with password authentication, which I don't recommend. So the best option is just to work with Shell link instead of SFTP link.
If you try to connect to a remote system where password authentication is disabled and public authentication is not configured properly, you will see fish: Waiting for initial line... on the console and then receive the following error message: Cannot chdir to "sh://user@host"
If you try to connect to the wrong port or wrong IP, you will only see fish: Waiting for initial line... and then the Midnight Commander UI will disappear and hang for some time.
To find out what went wrong, you can first use the ssh command to try to establish a connection. In most cases, you will notice that your SSH configuration is the culprit and not Midnight Commander. The error message you get with ssh will be more informative than the ones in Midnight Commander. Once you can connect via SSH, the Shell link feature will work as well.