Tuesday, February 3, 2015

Secure your Raspberry Pi


Recently I examined my Raspberry Pi's logfiles because of all the cyber warfare going on and as I went trough the auth.log (/var/log/auth.log) looking for failed login attempts I saw a list of about 100 attempts from IPs trying to login as root or bin user.

$ cat /var/log/auth.log | grep 'sshd.*Failed'

This got my attention and my awareness, of having an unprotected SSH server running open to the worldwide net. I decided to pay a little bit more attention to the security of my Raspberry Pi and here I'll show you a few easy steps to make your Pi more secure:

Changing the pi standard user

First you have to kill all processes running under your current user. Therefore it would be best for you to log in via SSH as root and then you have to find out the id of your pi user:

$ sudo su
$ killall -u pi
$ id pi

uid=1000(pi) gid=1000(pi) groups=1000(pi), ...

next you have to change the login user, group and the home directory to the new user called newuser and copy the contents of the pi user's home to the home of the newuser, then delete the old directory

$ usermod -l newuser pi 
$ groupmod -n newuser pi 
$ usermod -d /home/newuser -m newuser 
$ usermod -c REALNAME newuser
$ cp -r /home/pi /home/newuser 
$ rm -r /home/pi

Now you should be able to log in as 'newuser', but to still be able to use sudo, you need to change the user in /etc/sudoers from pi to newuser. This is only possible with the tool "visudo":

$ visudo

newuser ALL=(ALL) NOPASSWD: ALL


Set a hard password

Most important and most easiest thing to do, is to choose a strong password. You can change your current password by typing

$ passwd

and then set your new, strong password. Strong passwords usually contain
  • upper and lower case characters
  • numbers
  • special characters
  • more then 8 characters in length
  • and so on and so forth
Here you have a nice command that will give you a random password directly on your Pi:

$ </dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c12; echo ""


Changing the SSH port

One important action to avoid crawler which randomly test for open ports, is to change the standard SSH port from 22 to something else. This can easily be done either
  • directly via your routers port forwarding rule    or
  • by changing the SSH daemon's listening port

Directly via the router

Depending on your routers configuration you have to change the port forwarding from port 22 on your router to a random port (say 1337), which is not used by another service. By using this alternative, you don't need to change your sshd config on the Pi, you just have to change add the port-number when ssh-ing to the pi. Your router redirects port 1337 to port 22 on your Pi, and everything works as usual

$ ssh pi@my.duckdns.org -p 1337

Here a short overview over various services and their standard ports.

Changing the daemon

If you want to change the listening-port of the daemon directly, you have to alter the sshd config.

$ sudo vi /etc/ssh/sshd_config

replace Port 22 with Port 1337

Keep in mind that you also need to change the port-forwarding on your router to the port you selected.
If you want to open a connection you have to specify the port:

$ ssh pi@my.duckdns.org -p 1337

For your convenience you can create a $HOME/.ssh/config file and add the following:

Host rpi
HostName my.duckdns.org
User newuser
Port 1337

This enables you to connect easily from this computer:

$ ssh rpi

Adapt the SSH config

There are a few more things you can do with the sshd_config to improve the security of your Raspberry. As we are curious, we want to increase the logging level of our SSH daemon by changing following parameter from

$ sudo vim /etc/ssh/sshd_config
[...]
LogLevel INFO


to

LogLevel VERBOSE

After this change, ALL details of the login attempts will be saved to the auth.log file.

Allow and deny specific users

One great feature is to only allow specific users to login via SSH. Therefore you just have to add or change following lines in the config:

$ sudo vim /etc/ssh/sshd_config
[...]
AllowUsers Peter Jango

This line tells the server to allow only Peter and Jango to sign in via SSH. The next line does exactly the opposite:

$ sudo vim /etc/ssh/sshd_config
[...]
DenyUsers Peter Jango

Peter and Jango are not allowed to sign in via SSH, everyone else is allowed.

If you want to personalize your SSH login, then you can take a look at this tutorial, showing you how to customize the SSH login.

Restrict root access

Another important option, is to disable root access via SSH. It is still possible to login as normal user and switch to root or to work with sudo only. Just change the option "PermitRootLogin" to no

$ sudo vim /etc/ssh/sshd_config
[...]
PermitRootLogin no

$ sudo /etc/init.d/ssh reload


Limit number of connections

If an IP address tries to open more than X connections in XX seconds, we can tell the server to drop this connections. This can be handled by the MaxStartups option and can significantly alleviate DDOS attacks.

MaxStartups 10:30:60 (start:rate:full)

10 is the number of unauthenticated connections before we start dropping connections by a chance of rate/100 (30 %). Once there are 60 unauthenticated connections, we drop every connection. Because the Pi is on the lower end of the performance scale and isn't used as server for many users, I suggest to insert smaller values for start and full.

$ sudo vim /etc/ssh/sshd_config
[...]
MaxStartups 2:50:10

It also makes sense to reduce the LoginGraceTime, this is the time the server keeps the connection alive while waiting for authorization.

$ sudo vim /etc/ssh/sshd_config
[...]
LoginGraceTime 20


Disable password authentification - SSH keys only

A weak password is the biggest problem on SSH servers, so best thing would be to use SSH keys instead of passwords, because this keys are complex enough to withstand an average attack and together with the other configuration described above should provide a certain amount of protection. But the use of SSH-keys also comes with disadvantages: You can not log in from a device without pre-approving. Keep that in mind! To disable password authentication set

$ sudo vim /etc/ssh/sshd_config
[...]
PasswordAuthentication no

You can find a short tutorial about ssh-key authentication here.

Fail2ban

Fail2ban is a python based intrusion prevention tool, which scans logfiles like the auth.log and bans IPs that cause too many login errors by updating firewall rules (iptables) or TCP Wrappers (/etc/hosts.deny). It is very flexible, easy to use and has a lot of filters for various services like SSH, lighttpd, apache, vsftpd and so on.

You can download fail2ban on the fail2ban download page or simply install it on your raspbian by typing:

$ sudo apt-get install fail2ban

After installation is finished, we have to configure fail2ban, therefore go to the directory containing the config files (usually /etc/fail2ban/) and make a copy of the jail.conf with the name jail.local. Only change the parameters in the jail.local file, because changing the .conf file directly can cause errors on program updates and the parameters in the jail.conf get overwritten by the ones in the .local file. Here I will just talk about the basic options for SSH.

Look for the options regarding the SSH service and see if the filters are enabled and the logpath is set to the right place, usually /var/log/auth.log. I would recommend to set the maxretry parameter to 3 and the increase the time the IP is banned to e.g. 1800 (30 min). If you want to ban the IP forever you have to set a negative value for the bantime e.g. -1

$ sudo vi /etc/fail2ban/jail.local [...]
bantime = 1800
[...]

[ssh]
enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 3


You can find the filter rules in /etc/fail2ban/filter.d/ and you can create new ones for every service you like.
Find more information on www.fail2ban.org/wiki

I hope you found this useful and it will help you to stay secure!

Wednesday, January 28, 2015

How to bring back the "New Document -> Empty Document" menu in Gnome 3

Long time ago, the Gnome developers removed the right-click menu entry "New Document -> Empty Document" in Nautilus (the file browser). The solution to fix this is easy therefore it seemed not necessary to post it.
However, last week a friend told me that he hates Gnome 3 so much and as I asked why, one of the reasons was that this menu entry is gone.
So here is the solution (so that you start to love Gnome 3!):

  1. Create a folder called "Templates" directly into your $HOME directory if it does not exist
  2. Put a empty text file in there and name it "Textfile" (or anything else)
  3. Do a right click anywhere and be delighted with seeing "New Document -> Textfile"

The cool thing on this approach is that you can put any file with any content into the Templates directory.
Eg. you can put a template python script in there with the headers and scaffolding already in place, or a presentation with the company branding already applied... anything! Its universal!

Tuesday, January 20, 2015

Create a custom sandboxed webapp in Firefox

Google, Facebook, Twitter and others depend on getting as much information about you as possible and therefore use your account information to track and profile you not only on their services but also on 3rd party websites to fit the advertisement to your interests.
On this website you can check out how unique your browser is and how easy it is to identify and track you.
To make this a bit harder for them and save yourself the trouble of constantly logging in and out I will show how you can create a webapp with an independent profile for your Linux desktop.


It is very easy to create a custom launcher for each webapp and Firefox allows to create multiple profiles since a very long time. So in principle it is very simple and easy!

Let's do a webapp for Facebook! First, create a new Firefox profile, which will be used for the "Facebook-only-Firefox". Therefore, start the Firefox profile manager by typing:

$ firefox -ProfileManager

Now add a new profil 'facebook' and close the manager again. Next, create the launcher by copying the original Firefox launcher to the $HOME directory and rename it:

$ cp /usr/local/share/applications/firefox.desktop ~/.local/share/applications/facebook.desktop

Then we edit the facebook.desktop file and set the launcher name, the icon and the process how the application will be started. I suggest to get a nice icon for your application from the web and save it to ~/.icons/facebook.png. If the folder does not exist yet, create it!

$ vim ~/.local/share/applications/facebook.desktop

[...]
Name=Facebook
Exec=firefox -P facebook -new-instance www.facebook.com
Icon=facebook.png
-P profile-name opens firefox with profile "profile-name"
-new-instance opens Firefox in a new instance, as a separate process
Icon= If the icon is stored under ~/.icons/ there is no need to enter a path!

To immediately see you application in gnome-shell you can press Alt + F2 and type "r" and ENTER. This reloads the gnome-shell. Now you can use Facebook in its own browser, but don't forget to log out in your everyday browser ;)
To hide the tabs and therefore save screen space I recommend the Hide Tab Bar With One Tab addon.

NOTE:
There is one tiny problem you have to consider and which I didn't find a work around yet:
If you start the Facebook webapp and want to open your Standard-Firefox afterwards, it doesn't select the right profile. You could either change the firefox.desktop by copying to it to your $HOME as above and adding the default profile to the Exec line:

$ cp /usr/local/share/applications/firefox.desktop ~/.local/share/applications/firefox.desktop
$ vim ~/.local/share/applications/facebook.desktop

[...]
Exec=firefox -P default -new-instance
or you have to start the default firefox first and then open the webapp. Do you know a solution to this?
Happy socializing 2.0!

UPDATE:
Mozilla develops a webapp framework for their Marketplace that works in a similar fashion like we show here: Separate profile directory, minimal UI, own launcher,... The only difference is that they also create a separate binary and therefore do not have the multi-instance problem. A third-party developer (dietrich ayala) created an extension, "Standalone" which uses this framework to create webapps from any page on the web. Awesome!

Thursday, January 8, 2015

Customize SSH login

After you have set up a secure  SSH server maybe you would like to customize your login, to look a bit more personal. e.g. like the penrose triangle

     ____  ____  ____  ____                      ______________________
    /\   \/\   \/\   \/\   \                    /\                     \
   /  \___\ \___\ \___\ \___\                  /  \    _________________\
   \  / __/_/   / /   / /   /                  \   \   \                /
    \/_/\   \__/\/___/\/___/                    \   \   \__________    /
      /  \___\    /  \___\                       \   \   \    /   /   /
      \  / __/_  _\  /   /                        \   \   \  /   /   /
       \/_/\   \/\ \/___/                          \   \   \/   /   /
         /  \__/  \___\                             \   \  /   /   /
         \  / _\  /   /                              \   \/   /   /
          \/_/\ \/___/                                \      /   /
            /  \___\                                   \    /   /
            \  /   /                                    \  /   /
             \/___/                                      \/___/

 (source: wikipedia)


You can also create an ASCII Art from any picture. There are some sites where you can upload your picture and create an ASCII pic out of it, look here. Once you connect via SSH e.g.  > ssh user@myraspberry.pi you see the welcome text or logo, which is defined in your sshd config. First you have to create the file containing the hello message, e.g.  

 $ sudo vim /etc/ssh/welcome.msg  
     ____  ____  ____  ____                   |
    /\   \/\   \/\   \/\   \                  |
   /  \___\ \___\ \___\ \___\                 |
   \  / __/_/   / /   / /   /                 |
    \/_/\   \__/\/___/\/___/                  |
      /  \___\    /  \___\                    |
      \  / __/_  _\  /   /                    |
       \/_/\   \/\ \/___/                     |
         /  \__/  \___\                       |
         \  / _\  /   /                       |
          \/_/\ \/___/                        |
            /  \___\                          |
            \  /   /                          |
             \/___/                           |
WELCOME TO MY RASPBERRY PI!
PLEASE AUTHENTICATE!


In the next step, we have to tell our ssh daemon where to find this welcome message, therefore we have to change the 'Banner' entry in the sshd config to the location of our welcome message:

$ sudo vim /etc/ssh/sshd_config 
[...]
Banner /etc/ssh/welcome.msg


After that, we have to restart sshd:

$ sudo service sshd restart

We can also add another welcome message for the users, which are already authenticated by editing the MOTD file:  

$ sudo vim /etc/motd 

Once finished, we again have to restart the ssh daemon on the raspberry and then we can try this thing out. On connecting to our pi we should now see the pi ASCII logo and after entering the password, we should be informed about the news in our motd file.

Thursday, April 3, 2014

Ubuntu/Debian: Mouse buttons and trackpoint scrolling on T440s, X1 Carbon and all other new Thinkpads!

I just got a new Thinkpad T440s and was not very happy with it. No wifi, bad graphics and the touchpad was not working properly after installing Debian Wheezy, the current stable version.
I soon realized: Upgrading to Jessie is necessary to fix these problems. And it did - to a certain degree. Wifi was working (install firmware-iwlwifi), graphics were better, and also touchpad worked - but not as expected!

There are no actual mouse buttons on the new Thinkpad models. WHY would they do that? I hate touch and I hate pressing a whole oversized plate with a very bad haptic feedback which makes cracky noises. #whycopyapple
Further, whenever I pressed the touchpad down, the mouse arrow moved slightly which was really annoying. This is probably the Linux driver's fault, but still...
Most problematic: There is no middle mouse button scrolling any more. I hate moving my whole hand away from the keyboard just to scroll down a little bit. #hatetouchpads Pressing and holding the middle mouse button while just tapping the trackpoint a bit was so convenient!

How to make this a lot better:
Thanks to this post on Launchpad I got most of the problems somehow fixed. No more mouse moving while clicking, middle mouse button scrolling (yay!), you can even disable all the touch if you want.
All you need to do is to get the newest sources of the xserver-xorg-input-evdev driver, copy some files over from the xserver-xorg-input-synaptics sources and patch all of this with some work done by the arch linux guys.

In the end you just need to build the *.deb package and install it on your machine. You don't need to remove the original driver package! Also, don't forget to put the 90-evdev-trackpoint.conf file into /etc/X11/xorg.conf.d/ and reboot!

I already did all of the patching and building, so if you trust me (you can!) just install my packages on Debian Jessie 64bit:
Current (updated 28/01/2015) evdev version in Debian Jessie is 2.9.0, so download: patched_synaptic_amd64_debs_2.9.0.tar.gz
If you still use version 2.8.2 (eg. on Ubuntu), get this: patched_synaptic_am64_debs_2.8.2.tar.gz

PLEASE CHECK your dependencies and version numbers before installing! If the installation fails, you end up without mouse and keyboard input!

> wget http://homepage.univie.ac.at/s.hammer/files/patched_synaptic_amd64_debs_2.9.0.tar.gz
> tar -xzf patched_synaptic_amd64_debs_2.9.0.tar.gz
> sudo dpkg -i xserver-xorg-input-evdev_*
> sudo cp 90-evdev-trackpoint.conf /etc/X11/xorg.conf.d/


Have fun with your new Thinkpad!
PS: If you want me to build a 32bit package for you, please comment below!

Monday, January 20, 2014

HowTo manually upgrade the Moto G to Android 4.4 in Germany and Austria

Just today I read that it is easily possible to manually force the Moto G to a system update to get Android 4.4. All you need is to put the signed installer package on your phone under /sdcard/ and the Moto G will automatically move the files into the system memory and perform the upgrade.

So follow these steps:

  1. Download the upgrade package from here: http://d-h.st/JRE
  2. Move it to /sdcard/ either when plugged into your computer or with a file-manager
  3. Go to Settings -> About phone -> System Updates
  4. You will be asked to push the files into the systems memory and the update will begin
The installer package I linked above is a Germany/Austria specific package, I don't know if it will work for other countries too. If you current version in Settings -> About Phone -> System Version is also *falcon_umts.Retail.en.DE it will work for sure. If you have links for other builds, please leave a comment.

Have fun with Android 4.4!

Saturday, August 31, 2013

One-liner to convert any music file to mp3

On Debian 7 ffmpeg is not installed any more as it comes with its successor avconv.
Therefore it is enough to write a small bash for loop which takes any *.wma file of the folder and starts the conversion. The output file will then have the file extension replaced to mp3. Done!
The result looks like this:
for f in *.wma; do avconv -i "$f" -ab 192k "${f%.wma}.mp3"; done
However, you can replace the two occurrences of *.wma with any other music file format you want to convert from (eg: *.flac, *.aac, *.wav,...). Keep in mind that you need to have the right gstreamer plugin installed to encode and decode the desired formats.

Monday, July 29, 2013

How to manually install the OpenVPN binary

It seems that since the upgrade to Android 4.3 the OpenVPN Installer App is not working for me any more. I get some error saying /system cannot be mounted writeable (rw).
However, it is still possible to install the openvpn binary per hand... and it is not as complicated as it seems! This guide only works on rooted devices and is written for Linux users, however the lower part should also work on Windows and Mac.

At first you need to get the Android Debug Bridge binary and install it on your computer (I just put it into $HOME/bin).
Then download the latest OpenVPN Installer APK - we need to extract the openvpn binary from this package:
wget http://android-openvpn-installer.googlecode.com/files/OpenVPN-Installer-0.2.4.apk
To extract the xbin-binary, you can use FileRoller on Gnome or any other tool. Here is an example of how do it with the terminal only:
unzip OpenVPN-Installer-0.2.4.apk assets/openvpn-2.1.1-static-xbin
mv assets/openvpn-2.1.1-static-xbin openvpn
rm -r assets
Now use adb to push the binary to your phone/tablet's "sdcard" (external storage):
adb push openvpn /sdcard/
The next two commands will open a shell and give us root access on your Android device. Everything you type afterwards happens directly on your device, so be careful!
adb shell
su
Now we need to mount /system as writeable to be able to make changes. Next we copy the binary to its final location and delete it on the sdcard (unfortunately moving is not possible). After we changed the file-permissions so that the binary can be executed, we need to mount /system as read-only again:
mount -o remount rw /system
cp /sdcard/openvpn /system/xbin/
rm /sdcard/openvpn
chmod 755 /system/xbin/openvpn
mount -o remount ro /system
Everything should be done now. Close the connection to your device by typing exit two times and try to use OpenVPN Settings! The installer app will also show you "Binary installed" if everything worked!

Sunday, July 14, 2013

Rainy can't be built on Debian Wheezy any more - here is a solution!

To be able to build Rainy on Debian Wheezy (and probably also on Ubuntu), you need to do several preparations, because building now depends on NuGet (http://nuget.codeplex.com).
At first you need to install mono-complete, as this tool has many dependencies:

$ sudo apt-get install mono-complete

Then download the nuget command-line utility: http://nuget.codeplex.com/releases
Further create a file/script called "nuget" so that nuget.exe is called with our desired options:
#!/bin/bash
mono --runtime=v4.0 /usr/local/bin/nuget.exe "$@"

Copy both files (nuget and nuget.exe) to /usr/local/bin/ and make it executable:

$ sudo cp nuget* /usr/local/bin/
$ sudo chmod a+x /usr/local/bin/nuget


You now can already call nuget in your terminal. However, if it still creates an error, you need to download Microsoft.Build.dll and also copy it to /usr/local/bin. Get it, for example, here: http://headsigned.com/download/running-nuget-command-line-on-linux/Microsoft.Build.zip
This blogpost also explains how to extract the ddl from a working Windows installation in case you don't trust the previous source: http://headsigned.com/article/running-nuget-command-line-on-linux

Now you can try to make Rainy. If it throws an error not being able to download from https://something, import the certificates from Mozilla:

$ mozroots --import --sync

Now it should be able to build Rainy on Debian!

$ git clone https://github.com/Dynalon/Rainy.git
$ cd Rainy
$ make

Wednesday, April 10, 2013

Create a custom launcher icon in gnome-shell

Today, I realised that navigating into a certain folder to start mincraft with a terminal command is much to complicated. A nice minecraft icon within the other installed applications would be great!


All I needed to do was to create a file: ~/.local/share/applications/minecraft.desktop and fill it with such a content:
[Desktop Entry]
Encoding=UTF-8
Name=Minecraft
GenericName=Game
Comment=Block Building Game
Exec=java -Xmx1024M -Xms512M -jar /path/to/minecraft.jar
Icon=/path/to/minecraft/icon.png
Terminal=false
Type=Application
MimeType=text/plain;
Categories=Game;
Name[en_US]=Minecraft
You still need to download a beautiful icon and adopt the two lines in bold (path to your executable and to the icon). Further you need to run
chmod a+x ~/.local/share/applications/minecraft.desktop
to give this file proper rights for execution. This is it! It works for any other application/script too!

Wednesday, February 27, 2013

Tomboy's new sync-server Rainy running on the Raspberry Pi!


As Ubuntu One is shutting down their note-sync service based on the Snowy server, I needed to come up with a solution for this problem. My main thought was: Why should I trust anyone on this again, if it is so easy to build your own "cloud" for syncing notes?
Rainy is still in early development, but already does an awesome job on syncing notes between Tomboy and Tomdoid. Special thanks to Timo Dörr for this! Further, the Raspberry Pi (a credit-card sized computer) is the ideal platform for this purpose as it only "eats" 2 Watts per hour and can be easily run 24/7.

How do I build my own note-sync-server?

To create a minimal Debian system on a SD Card for the Raspberry Pi, just follow the steps here: 
http://blog.kmp.or.at/2012/05/build-your-own-raspberry-pi-image/

In summary you need to:
1. Install these dependencies on your computer: 
apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools
2. Adopt the script (Optional! Just search for the lines and put your things in there!):
x) Change the debian mirror url: deb_mirror="http://http.debian.my/debian"
x) Add the network interface wlan0 for wifi access and use a static IP address of your choice:
echo "auto lo
iface lo inet loopback

#auto eth0
#iface eth0 inet static
# address 192.168.0.4
# netmask 255.255.255.0
# gateway 192.168.0.1

auto wlan0
iface wlan0 inet static
address 192.168.0.4
netmask 255.255.255.0
gateway 192.168.0.1
wpa-ssid MYSSID
wpa-psk MYWIRELESSKEY
" > etc/network/interfaces

    x) Change the password: echo \"root:MYPASSWORD\" | chpasswd
    x) Add packages to pre-install for wifi (you might need other firmware packages!): 
apt-get -y install locales console-common ntp openssh-server less vim wireless-tools firmware-atheros firmware-realtek wpasupplicant
3. Run script: sudo ./build_rpi_sd_card.sh /dev/sdX
4. Put the SD Card into your Raspberry Pi and plug it in. It should automatically connect to your wifi (or lan)!

After you logged in (either directly or over ssh root@192.168.0.4), you will see a typical Linux shell. At first we will have to install the dependencies and necessary packages for our mono based Rainy server:
apt-get -y install libmono-system-runtime2.0-cil libmono-microsoft-csharp4.0-cil libmono-system-componentmodel-dataannotations4.0-cil libmono-system-web2.0-cil libmono-system-web-services4.0-cil libmono-system-data-linq2.0-cil libmono-system-data-linq4.0-cil libmono-system-web-abstractions4.0-cil mono-runtime unzip screen
Then we have to download the pre-compiled Rainy binary, unzip it and change into the directory:
wget http://rainy.notesync.org/release/rainy-0.1.3.zip
unzip rainy-0.1.3.zip
cd rainy-0.1.3
With a text editor of you choice you can edit the settings.conf file to change the user names, passwords, etc. Then start Rainy:
mono Rainy.exe -c settings.conf
If you want to run the server as a background job, I suggest to use screen. A very short explanation on how it works can be found here: http://jjjjango.blogspot.co.at/2013/01/linux-start-long-running-jobs-with-ssh.html

Now open your Tomboy, or Tomdroid and add the new sync server URL:
http://192.168.0.4:8080/<username>/<password>/
If you want to sync from outside your home, you have to redirect the 8080 port of your router to the IP address of the Pi. Further, you have to use the public IP of your router in the sync URL. In case you get a dynamic public IP, you will have to use http://www.noip.com/ or a similar service.

I hope, you know what to do! If not, please don't hesitate and ask your questions in the comments!

Friday, January 25, 2013

Insert a CD image file in gnome-boxes

As I heard about the new Age of Empires II extension "Forgotten Empires" created not by Microsoft, but by an awesome community, I needed to play this game again! I don't like Wine that much as I once got a bunch of viruses having it just installed, therefore I decided to install Windows XP in a virtual machine.
I chose GNOME Boxes as it uses kvm. It was really fast and easy to install, I just needed my Windows-Installer-CD as an *.iso file.

However, I could not find any option to insert another *.iso image file to be mounted in the guest system. The user interface just does not provide to change the CD disc image - so we have to change the kvm options in another way. Open your terminal and type:

$ virsh edit Windows\ XP\ Pro.iso

(If you installed something else than Windows XP you might have to look in the folder .local/share/gnome-boxes/images/ how your machine is called.)
In this file search for the lines saying something like the following and exchange your iso-filename (+path):

<disk type='file' device='cdrom'>
   <driver name='qemu' type='raw'/>
   <source file='/home/tux/AoE.iso' startupPolicy='optional'/>

(If you need help using vim, check this out.)
Save it, reboot your Windows and enjoy having your disc image in the CD drive of the guest!

Friday, January 18, 2013

Linux: Start long running jobs with SSH

Recently I needed to start several long running jobs at my working machine from home using SSH. Unfortunately closing the SSH connection stops all the tasks started in this session.

Therefore we need a tool to start some tasks which will be kept running upon logout: SCREEN
There are tons of tutorials and howtos out there and a man page exists too.
However, here the most important commands and shortcuts:
Start it with typing

$ screen

then start your job, then press Ctr + A, Ctr + D  to detach the job and close the program without killing the running task. Running

$ screen -r

will resume your previous session.

Ctr + D closes the session and kills all tasks.
Ctr + A, Ctr + C opens a new screen "window",
Ctr + A, Ctr + N moves to the next window,
Ctr + A, Ctr + P moves to the previous window,
Ctr + A, Ctr + D detaches the task and closes the window,
Ctr + A, ESC enters scroll mode: use Up/Down/PgUp/PgDn to scroll, ESC again to exit this mode

Friday, November 23, 2012

Windows as Guest in Linux with minimal Software

You have Linux (any distribution, commands below for Debian/Ubuntu) and need to do just one tiny thing with Windows? Therefore you don't want to install thousands of packages and third party packages?
Then follow this quick guide made out of 4 steps and one package you need to install!

Fist install the kvm engine typing this into a terminal:

$ apt-get install kvm

Afterwards change into the directory where you want your virtual harddrive image to be created. The next command will create a *.img file with a size of 8GB.

$ dd if=/dev/zero of=vm_disc.img bs=1024k count=8000

Once this is done, you can boot up your virtual "machine" for the first time - of course with the Windows Install CD "inserted" into your device:

$ kvm -m 2048 -cdrom Windows_XP.iso -boot d vm_disc.img

Remember that you might have to exchange the name of your install-cd image.
Reading the manual of kvm (terminal command: man kvm) I found some nice features like graphical output to a vnc stream, using a specific sound-card, forwarding usb devices,... I am always using following command to start my virtual machine:

$ kvm -m 2048 -hda vm_disc.img -vga std -soundhw ac97 -usb -usbdevice tablet -smp 2 -vnc :0

Afterwards I connect to the vnc stream (localhost) using the "Remote Desktop Viewer" application.
Source: http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/

Have Fun!

VLC as DLNA Client on Linux

Since version 2.0 VLC is able to play content from a DLNA Server.
On Ubuntu it seems not to be working out of the box. The first challenge is to realize, that a probably installed firewall (eg. ufw) is blocking all incomming traffic, meaning the broadcast of the DLNA server is not seen.

Add a rule to the firewall, to enable incoming traffic on port 1900 UDP for your media-server IP.
Therefore you might want to use a graphical user interface like gufw installable either in the Software Center, or with the terminal: 

$ sudo apt-get install gufw

Afterwards VLC should be able to see your DLNA server, but when double clicking, it seems that nothing happens. But this is not true - if you look more closely, you will realize that you suddenly have a lot of wlan/lan traffic. VLC is syncing the database without any graphical feedback. This is not really user-friendly.
After some time (depended on the size of your database, so be patient...) a folder icon appears, double clicking on it takes a looong time again. This process without graphical feedback (again!) is finished when you see a triangle in front of the folder... YAY! 

Now you can browse your database and start a movie, songs and even look at images!

Have fun!


Tuesday, November 6, 2012

Save the environment AND your eyesight!

I have to read a lot lately and therefore I print out everything. I don't like to read publications, papers and other scientific stuff on the screen, as there is no easy possibility to take down notes, mark some lines and interact with this thing. I just like to work with paper and pencil!

To save the environment a little bit, I always print two pdf pages onto one sheet - double-sided of course - leading to 4 virtual pdf pages being printed onto one single sheet of paper.
This is awesome, but my eyes start to hurt after some time, because the text is so unbelievably small. However, I realised that there is a lot of white space on these sheets and somehow it should be possible to remove the white space and "zoom" the pages a little bit for a better readability.

Exactly this is done by pdfcrop (http://pdfcrop.sourceforge.net/)!
You just type something like

$ pdfcrop --margins 5 input.pdf output.pdf

into your terminal and then print the output.pdf as usual. You will realise that the font size has almost doubled (or sometimes even more), only with removing the white borders. Happy reading!

Saturday, June 23, 2012

Switching graphic cards on the Thinkpad T400

I just realised that a lot has changed since I looked for support of Hybrid Graphics under Ubuntu/Debian a few years ago. Now, there is a project for switching between the integrated and discrete graphic card called vgaswitcheroo!

In the BIOS settings you have to select "Switchable Graphics" and the computer will boot up with the internal graphics card (in my case Intel 4500) turned on.
With one simple command, you can then switch to the discrete graphics (ATI Radeon HD 3400). The only expense at the moment is, that you have to log out and in again to restart the x-server.

To switch to the discrete graphic card open the Terminal and type:
sudo echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch
Then log out and in again. You can then check your running graphics card under "Details" in the "System Settings" (running Gnome 3.2 or higher).

To switch to the internal graphics type:
sudo echo DIGD > /sys/kernel/debug/vgaswitcheroo/switch
Thanks for this awesome tool!
Source: https://help.ubuntu.com/community/HybridGraphics

Do you want to automate things?

I created a shell script, which detects the running graphics card and asks you whether to switch or not!
Download it, make it executable and run it as superuser! I commented every piece of code to make it readable for you.
Download: https://github.com/j-4/scripts/blob/master/switch_graphics.sh

Have fun!

Saturday, June 2, 2012

Most perfectly fitting Raspberry Pi Paper Case

Previously I downloaded the famous Punnet paper case (http://www.raspberrypi.org/archives/1310), but unfortunately it was not really fitting. The base area was too broad and the holes for audio out, HDMI and micro USB not properly placed.

Therefore I measured the whole Raspberry Pi in detail and quickly drew a case based on the Punnet, but without the annoying bugs.



You can choose which file to DOWNLOAD:

I think you are smart enough to figure out where to cut, fold and glue ;-)
The case has to be folded in a way that the lines are inside!
Keep in mind that you uncheck "Fit to printable area", and that you do not use scaling for printing.

Further, if you glue paper edges above the HDMI and the micro-USB plug, the board is even more stable in the case! There is no wobbling or squeezing (See photos for details).

Here some photos of the resulting paper case:




This case, as well as the all blog-entries, images,... are published under the Creative Commons License: http://creativecommons.org/licenses/by-nc/3.0/

So, if you still find a bug, just download the *.svg and fix it (or comment here)!

Thursday, May 24, 2012

Android Camera App complains "Please insert an SD card..."

Today my Android phone running Oxygen Rom 2.3 could not make photos any more. A error message appeared on opening the camera app: "Please insert an SD card before using the camera", although the sd card was present and also detected by the system.

When mounting it on my Linux system, I could not delete any files and the error appeared: "read-only file system".
A little research revealed, my fat32 filesystem got corrupt somehow, but this can be easily fixed:
sudo fsck.vfat /dev/mysdcard -v -r
(please unmount the partition before and change /dev/mysdcard to the value of your device! you can see all your mounted partitions with running the "df" command!)

On Windows, there might also be a button somewhere saying "Repair File-System".
Mount SD card, boot the phone and it should be fixed!

Saturday, March 10, 2012

Ubuntu/Debian: Bluetooth disabled by default!

I found this really useful post here: http://ubuntuforums.org/showthread.php?t=1333221
If you ask me, it would be best if GNOME remembered the last state of the devices across reboots.

"How to set bluetooth radio default off (after booting)?

As superuser edit the /etc/rc.local file add this line before exit 0:
rfkill block bluetooth
This will keep bluetooth turned off when you boot/login but you can still turn it on at will with the bluetooth applet in the panel!"

Please make sure rfkill is installed:
sudo apt-get install rfkill