Generate SSH Keys…

Recently I needed to do password less login for services to be automated. I could make scripts run in cron jobs, which could run in the middle of the night.

Any good operating systems, like a Linux, Mac OSX, freeBSD etc will have ssh built in.

To generate the ssh key file is a simple process. Then you just need to copy the generated file to the destination machine.

Step One:
Generate the SSH keyfile

When you generate the key, it will ask you to type a password for the ssh key. Most people like I do not type a password/paraphrase due to you need to add this later into a script.

I change the encryption bit from the default 2048 to 4096. You can add more encryption but remember the more you add, sometimes it takes longer to log in as the host machine needs to process the keyfiles.

Once this is done you need to copy the file to the remote/destination machine.

Step Two
Copy the newly created keygen file to the remote/destination machine.

Once your public ssh key has been copied across, you now can use passwordless logins across your machines. Enjoy…

Convert Iso to VirtualBox Vdi

A issue recently is I have been playing with some new distributions as I have been doing more development using linux as my desktop operation system.

Before I would commit to using a new distribution os my main laptop operating system. I have been trailing them as virtual systems on VirtualBox.

Some of the distributions only come on live iso images, with no installation application. So my solution was to convert the live iso image into a VirtualBox vdi. The process is only one command to convert the iso to a vdi file.

Step One:
Locate the live iso image for conversion to a vdi file..

Once this is complete you want to add this to your VirtualBox machine. When you create your virtual machine, instead of creating your new your new vdi file, load the newly created vdi file.

Enjoy…

Move your Ubuntu system to a new machine.

ubuntu logo

Recently I changed Ubuntu laptops, where a simple dd would not have worked due to the large changes in hardware, like going from non efi to a efi system. So the disk structure had to change. Why doing a disk image was ruled out.

I worked out a way after some google searching that it was best to install a basic installation of Ubuntu 16.10 on the new laptop then, create a list of the packages I had installed upon the old laptop, which I could use to install upon the new laptop.

Once this was done, all you need to do was transfer your data and any configuration files to the new laptop.

Below is a method I used with the commands to replicate the packages from the old system to the new system.

Step One:
On the old machine run this command to make a list of the packages that exist.

You also need to copy from the old machine the /etc/apt directory. This has any repositories etc that are custom added like Mariadb as a example.

Step Two:
Now copy the files across to the new machine. Replace the /etc/apt directory from the old machine.

After you have done this with the pkglist file you can install the packages with the following command.

There is a chance that packages will not be found or it will crash during installation. To get around packages that are not found, you need to edit your pkglist file to continue with package installation. When a package crashes during configuration/installation. You need to kill the dpkg process then type the following command:

This will fix the current installation/configuration issues. You can then restart the command from step two to continue installation of packages.

Step Three:
You can now copy your configuration files and anything else from your old machine to the new machine.

A easier way long as there are not too many files in your machine would be to just archive your home directory and copy the archive file to the new machine and un-archive it in your home directory. This is easiest as there are a lot of hidden files in your home directory.

Now enjoy your new machine.

Auto Start VirtualBox VM’s…

logo-virtualboxI have started using virtualbox more and more for development work, and started getting a bit cheesed off on how to auto start the virtual machines on my server. Server being headless, I thought there would I would create some initialisation scripts under ubuntu get the job done. Then I thought, that someone else has already done this. Why reinvent the wheel, when the wheel has been invented.So a quick google search brought to a webpage that allowed me to start the vm’s when the host server starts up. The link to the original page is here The page is exactly what I needed but it missed a few steps that I have added here to simplify installation.

The issue is if you are not a root user you need to change the “VBOXUSER” in the above script, to the user you want.

If you have not added the user to the vboxusers on the host system the command is

Once this is done you need to add the script to the right /etc/rc*.d directories. This can be done simply with the command.

Once this is done, you should be ready to go unfortunately not. There is still one more process and that is populating the init script config file so it knows what virtual machines you have to start up. The following command I used to startup any unstarted virtual machines so the init script knew about them.

Once this was done you can run the init script if needed to test all your virtual machine startup.

Enjoy…

OS X 10.8 Mountain Lion…

apple logo
Apple Logo

I decided to update my macbook air 11″ with 2gb of ram to OS X 10.8 mountain lion. So far the impression is, that it is faster in speed than 10.7 lion.  I have not made any use of the new features like notifications. Which is supposed to intergrate social media into Mountain lion. I found all software I use could run on Mountain lion. I did have to update a few of these to a later version, but that was just some time, it took for this to happen via the App store.

Xcode command line tools…

apple logo
Apple Logo

Seems there is a issue when you install the xcode developers tools from the Apple app store, it does install the command line tools, if you want to run apps like homebrew etc. You do not need the command line tools to install homebrew, but you do need the command line tools.

To install the command line xcode tools. You need to start up xcode, the go file > preferences > downloads and the click on install Command line tools. Its that simple. Just sit back, wait for about 100mb to download and install.

XQuartz is the new X11…

xquartz logo
Xquartz Logo

With my upgrade to 10.8 OS X Mountain Lion, one of the downside I found as a Unix System Administrator is that Apple have decided not to package X11 into the operating system anymore. I require X11 to run X apps to my OS X desktop. After some google searching X11 is now a seperate package. You need to download the XQuartz package from here http://xquartz.macosforge.org/landing/ Once downloaded, just install and reboot your Mountain Lion machine and reboot.

Install ufw firewall on Ubuntu…

ubuntu logo

I updated my 10.04 LTS servers recently to 12.04 LTS. One of the issues I have is that when I upgraded my iptables script failed. I decided that I would, try and fix my iptables, but iptables changed so much from 10.04 to 12.04. After many days of screwing around, I gave up and looked at alternatives to get my firewall working again. I found ubuntu had a product called Ubuntu Firewall. To get ufw and working, is not a hard task. Howto is shown below.

You need to enable ufw

Now if you want to allow ssh port open, so you can make a remote connection to the server.

To see the the current status and list of what ports are open

If your like me and running the server also as you gateway, you may only want to block the interface to the outside world and open all ports on the internal interface.

This does not do any nat traversal/masquerading. I will blog about this later.

Replacing a disk in a Software Raid Array…

logo-linux01A disk recently died on my software raid array, and replacing the disk was a simple procedure. You will get some notification via your systems email regarding that a disk has failed. Usually you can periodically check the mdstat file and see if any disks have failed. You can check the mdstat file below.

The output should be similar to below.

You can see from up above that one of the disks has died. Going by the sequence of disks in the /proc/mdstat file. I can make out that /dev/sdg1 has failed ( I have gone a bit ahead on the sequence). I now need to remove /dev/sdg1 from the array. You do not need to stop the array to remove the disk. The command below to remove the disk is

Unless you have hot swappable disks, you need to shut down the system to swap the old disk out and replace it with a new disk. Once the system is rebooted. You can type the command to add the new disk the existing array.

This will take some while for the disk to resync with the existing array. To monitor the progress of the array, you just type in the following command.

You can ctrl-c to get out of this anytime. It wil update every ten seconds.

Reset Network Drivers to eth0…

Recently I came across a issue, where a added a dual network card to my ubuntu server and instead of taking over the eth0 and continuing down the line in sequence. Ubuntu decided to just continue the sequence of eth1 and eth2. So it got me wondering why does it not take over the eth0, since the old network card is not there. It seems the culprit is the udev rules and the network cache which remembers the mac address of the previous card and leaves that eth0. So no other ethernet card can be eth0, till you delete the network cache and udev regenerates the device with the new network card. To resolve this issue you just need to delete the fie below and reboot.

# rm -f /etc/udev/rules.d/70-persistent-net.rules