Emulate a computer that runs a linux based operating system to use any command-line application you want!
Combine a powerful console emulator and a script that let's you manage your linux virtual machine easily, in order to create a comfortable experience.
Enjoy to run linux based applications on your windows system and create new workflows that make you even more efficient than you are already.
Oracle VM VirtualBox is a software that let's you create a virtual machine - that is essentially a computer inside your computer. This VM in turn can run our beloved linux based applications.
Cmder is a neat console emulator that supports many features the default windows console lacks. (e.g. shortcuts, aliases, and many more)
Getting multiple programs to work together can be a frustratingly tedious process. That is why I have created a batch script that let's you control your linux VM easily.
To make MiniLinux work, these programs are important:
VirtualBox will emulate a computer (=virtual machine) running a linux operating system, that will run the beloved linux based console applications.
Cmder is a console emulator for windows. It provides a neat looking console that is, in many ways (shortcuts, ...), superior to the default windows command-line (cmd). It comes in two flavours, of which I prefer the full version that comes with built in tools like git, ssh and many more.
The full version of cmder comes with ssh, therefore it's not necessary to install it seperately.
The VM is the core of MiniLinux as this is what really executes the linux command line applications.
To use as little system resources as possible, I chose to use the minimal version of Ubuntu as operating system on the VM.
Short summary: | |
---|---|
VM Name | MiniLinux |
Hostname | minilinux |
Full name for User | MiniLinux |
Username for account | user |
Password for account | password |
Screenshots of the Ubuntu 14.04 minimal installation:
sudo apt-get update && sudo apt-get upgrade
The setup of the ssh connection can be broken down to three parts:
Install openssh
sudo apt-get install openssh-server openssh-client
Establish a virtual connection between the windows host and the linux guest
Connect via ssh
Use the following command (in windows & cmder) to connect:
ssh user@192.168.56.1 -p 4022
The authenticity of host '[192.168.56.1]:4022 ([192.168.56.1]:4022)' can't be established.
ECDSA key fingerprint is SHA256:VdtF0c7Ptik3rGZMXAqjH+OFocq9Kj2NIdYXh7QEYvE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.56.1]:4022' (ECDSA) to the list of known hosts. user@192.168.56.1's password:
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-86-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sat May 14 14:31:09 2016
user@minilinux:~$
Install Guest Additions
sudo apt-get install virtualbox-guest-utils
Unless you deny other machines access to the VM, anyone could connect. Because I don't really appreciate anyone except myself connecting to my MiniLinux VM, I'll refuse ssh-connections that do not come from my machine.
Restart the VM, before you continue with this procedure!
The first step is to figure out the host IP:
grep ssh /var/log/auth.log -a | tail | grep Accepted
This should give you something similiar to this output (line count may vary - as long as there is at least one line):
The host IP is 10.0.2.2 in my case. If your host-IP differs, replace all occurances of 10.0.2.2 in this segment with your host-IP.Jul 12 07:54:25 minilinux sshd[916]: Accepted publickey for user from 10.0.2.2 port 65199 ssh2: RSA SHA256:3GycrTkwpgsGsQc3Fpt6UWqMhooEvhCthztogo/xY4g
Jul 12 08:18:59 minilinux sshd[1037]: Accepted publickey for user from 10.0.2.2 port 49930 ssh2: RSA SHA256:3GycrTkwpgsGsQc3Fpt6UWqMhooEvhCthztogo/xY4g
Jul 12 08:38:42 minilinux sshd[1201]: Accepted publickey for user from 10.0.2.2 port 50507 ssh2: RSA SHA256:3GycrTkwpgsGsQc3Fpt6UWqMhooEvhCthztogo/xY4g
Now simply add sshd: 10.0.2.2
to /etc/hosts.allow
and sshd: ALL
to /etc/hosts.deny
.
echo "sshd: 10.0.2.2 # Host PC" | sudo tee -a /etc/hosts.allow
echo "sshd: ALL" | sudo tee -a /etc/hosts.deny
Create a ssh-key
I do not want to use my main ssh-key for this purpose, as it is password-protected (which you should do too). Therefore I will create a second ssh-key without password protection that will only be used to connect to the VM. Remember to specify a location to save the key. Otherwise it will overwrite your existing one! Then leave the passphrase empty.
ssh-keygen
Enter file in which to save the key (/c/Users/MyUser/.ssh/id_rsa): C:\Users\MyUser.ssh\id_rsa_minilinux
Enter passphrase (empty for no passphrase):
Enter the ".ssh" directory of your windows machine
cd /c/Users/MyUser/.ssh
Copy the public key to the VM
ssh-copy-id -i id_rsa_minilinux.pub localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is d2:0d:83:f4:21:95:3c:63:6f:bc:f1:5f:0e:96:c1:e8.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
user@localhost's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'localhost'" and check to make sure that only the key(s) you wanted were added.
Disable GSSAPIAuthentication
Authenticating with the public key took up to 15 seconds for me. After I disabled GSSAPIAuthentication with the following command, connecting worked in under a second!
echo "GSSAPIAuthentication no" > config
Try connecting via ssh
On Windows:
ssh user@192.168.56.1 -p 4022 -i C:\Users\MyUser\.ssh\id_rsa_minilinux
Mount Shared Folder
Create folder where the shared folder should be mounted
mkdir /c
Mount shared folder
sudo mount -t vboxsf -o rw,uid=1000,gid=1000 C_DRIVE /c
Check whether mount worked
Enter the folder
cd /c
Create a folder
mkdir MiniLinuxTest
Check if the folder was created
ls -la
Remove the folder:
rmdir MiniLinuxTest
Automatically mount the folder at startup
add sudo mount -t vboxsf -o rw,uid=1000,gid=1000 C_DRIVE /c
to "/etc/rc.local"
sudo
without password promptDo note that may not want to do this, as you are likely less hesitant to write sudo
in front of a command before revalidating that you typed the command correctly, if you do not have to enter a password.
Nevertheless, I consider it a good balance between having to type a password every time i want do use sudo
and using the super user per default (sudo -i
)
Write user ALL=(ALL) NOPASSWD: ALL
in the last line to the file opened by sudo visudo
.
sudo visudo
Download the script and the config file and add the folder they reside in to your windows PATH variable, in order to access it with linux
anywhere.
Instead of only downloading the scripts seperately, you can also clone the entire MiniLinux repository to get eventual updates.