How To Change/Override Linux Password from other Linux PC

Or if you have linux running on an SD card (e.g. Raspberry Pi) and you want to change the password from another your Linux PC, here’s how to do it.

1. Mount the target system on your linux PC. If it’s a Raspberry Pi SD card, simply plug it in. Now let’s say the mount point is /media/stick, and inside that folder you will find system folder such as /etc, /dev, /proc, and others.

2. Information of user and passwords in most linux systems are kept in a text file, consecutively /etc/passwd and /etc/shadow. What we need to change is the latter. Open the shadow file (use sudo cat /etc/shadow), and see the entry for the user whom you want to change the password. The entry contains 9 fields, separated by colon (“:”). More detail on this type man shadow on terminal. Our interest lies on the second field, which is the encrypted password field. This field has format of following:


Now look into the format of your shadow file, if the id is 6, most likely SHA-512 encryption is used. The other possibilities are MD5 (id 1) and SHA-256 (id 5).

3. We will use mkpasswd, a front-end for crypt, the function for linux password encryption. To create a new password with SHA-512 encryption, do this:

mkpasswd -m sha-512 <password> <salt>

You can pick anything for the password, but for salt you need to give 8-16 random sequence of characters. If salt is empty, mkpasswd will generate a random salt, hence everytime you call mkpasswd it will give different result. For shadow, make sure you give in your salt. For example:

ariandy@linux:~$ mkpasswd -m sha-512 mypassword OhIuVG9LLE79.5XV

Now put this output in the second field of /etc/shadow file. Note that hashed password contains no colon, because colon is the delimiter between fields in shadow.


Raspberry Pi Backup and Restore from Linux

0. Preparation

Before backing up the SD Card of Raspberry Pi, do clean up the system first to remove unneeded files such as package source codes and apt-get caches. You might be surprized by how much apt-get is keeping cache of downloaded packages. It was nearly 600MB for me. Cleaning this up would give you smaller backup image.

df -h
sudo apt-get clean
df -h

See how much space you free’d after cleaning apt-get’s cache.

I like to keep a piece of information, that tells me that the system is in the state of just being restored. I do that by either editing the MOTD (Message of The Day) or making an empty file on my home folder “THIS_IS_JUST_RESTORED”.

To back up the SD Card, first plug the SD Card into the SD Card reader of your laptop/PC that runs Linux. I use Ubuntu 12.04 Precise Pangolin. Then get any files that you need to copy, after that unmount the SD Card. Default Raspbian installation has 2 partitions made on the SD Card, so do not forget to unmount both. To check which folder is mounted to which device, use df -h and see the lines that start with /dev/mmcblk0p1 and /dev/mmcblk0p2. Then unmount the corresponding folders:

sudo umount /media/first_sd_partition
sudo umount /media/second_sd_partition

1. Backup

To back up the SD card, what we are about to do is making an image of the device, in this case both of the SD card partitions. For Linux, we have dd. I personally use dcfldd, an enhanced version of dd. It gives progress percentage, and also multiple on-the-fly hash calculation. To install dcfldd, in ubuntu simply:

sudo apt-get install dcfldd

If you want the backed up image to be as small as possible, you have to compress the image of the SD card. In Linux it is possible to compress an image which is currently being backed up (on-the-fly compression). With this you can save your hard disk space, because if you’re making an image without on-the-fly compression, you will require at least the same size as the SD card. If your have 8GB SD card, although only used partially, the resulting image from dd or dcfldd will be around 8GB in size.

To backup with on-the-fly compression:

sudo dcfldd bs=4M if=/dev/mmcblk0 hash=sha1 hashlog=./image.img.sha1sum | gzip > image.img.gz
sudo sync

And we’re done.

Everytime after you run dd or dcfldd, do not forget to call sudo sync to flush system buffers. I forgot to do this once and my system goes all crazy and weird.

If you want to do it the long way, you can do backup without compression:

sudo dcfldd bs=4M if=/dev/mmcblk0 of=./image.img hash=sha1 hashlog=./image.img.sha1sum
sudo sync

Then if you realize that it takes too much space, you can compress it anytime with gzip:

gzip image.img

Please note that it will take a while, since we’re dealing with gigabytes of data.

I also like to watch the image file grow in real time, so I do this:

watch ls -lh image.img*

2. Restore

If you have your image file already compressed, you can either uncompress and then restore, or uncompress while restore.

I find uncompressing and restoring in the same time (on-the-fly) is the most efficient way:

gunzip -c image.img.gz | sudo dcfldd bs=4M of=/dev/mmcblk0 hash=sha1 hashlog=./hash.log
sudo sync

Again, do not forget to flush the system buffer by calling sudo sync.

This hash thing, is for making sure that the backed up and restored image are consistent, not broken in any way which might happen during transfer/copying or upload. After the process finished, compare both of the hashes (image.img.sha1sum and hash.log) and make sure they are identical. You don’t need to read both files manually, just tell linux to do it:

diff -sq image.img.sha1sum hash.log

This will tell you either both files are identical or not.

If you are bored and have a lot of free space in your hard disk, you can do the restoring process in the long way by first uncompressing the image, then write it to the SD card:

gunzip image.img.gz
sudo dcfldd bs=4M if=./image.img of=/dev/mmcblk0 hash=sha1 hashlog=./hash.log
sudo sync

Setting Up WiFi Access Point with Edimax EW-7811UN on Raspberry Pi

I am running an image processing algorithm on my Raspberry Pi and I need to access it wirelessly (wired connection is sooo ’90s :p ). So my requirements are following:
– WiFi Access Point for remote access
– no need internet connection
– runs on Raspbian Wheezy

1. Configuring network
Edit /etc/network/interfaces, remove anything related to wlan0 then add this lines:

iface wlan0 inet static

Although the configuration is already defined, sometimes it won’t be applied by the system upon booting. To make sure, add ifup wlan0 inside /etc/rc.local file before exit 0 so it will look like this:

#!/bin/sh -e
# rc.local

# add this
ifup wlan0

exit 0

2. Installing DHCP Server and “DNS” Configuration
DHCP is the one that is responsible to give out IP addresses to clients who are connected to the Access Point. Meanwhile, DNS or Name Service is working as some kind of dictionary, that translates numbers of IP address into human-readable names that are easy to remember and to type.

This time I will use dnsmasq for easy and fast DHCP+DNS deployment.

sudo apt-get -y install dnsmasq

After installation it will run the daemon automatically. Stop it and then we work on the configuration:

sudo service dnsmasq stop
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo touch /etc/dnsmasq.conf

Now edit the newly created dnsmasq.conf config file. For minimum setup, this should be the content of the config file:


For full configuration options, you can refer to the original config file (dnsmasq.conf.orig).

Although is easy enough to remember, isn’t it easier if we use “raspi” as address? So then you can simply type ssh raspi or http://raspi/. To make this happen, edit /etc/hosts file, append with this:        raspi raspberrypi raspi.local raspberrypi.local

3. Installing hostapd
This WiFi USB Dongle from Edimax uses Realtek chipset, it is rtl8192 to be precise. Kindly enough, Realtek has provided hostapd implementation which is specific for this chipset.

For installation instructions, I suggest you to follow Jens Segers’ blog post.

After finishing installation, edit the hostapd configuration file to fit your needs.

Getting Raspberry Pi, OpenNI2, and Asus Xtion Pro Live To Work Together

UPDATE Feb 28, 2013:

– It works on my 256MB Raspberry Pi with Asus Xtion Pro Live tested through powered USB Hub from Belkin.
– Camera viewer that is shipped with OpenNI (NiViewer or SimpleViewer) will not work because it’s built with OpenGL. Raspberry Pi doesn’t support OpenGL. So to get camera visualization we have to use OpenCV. In the source above he uses OpenCV from raspbian repository. But since I’m gonna do image processing with OpenCV so I prefer to install it manually.
– Building OpenNI2 from source will take a lot of time. To save the fuss you can grab the pre-compiled Raspberry Pi package from Hirotaka’s website above (OpenNI version 2.0.0), or my package (version 2.1.0, size ca. 1.5MB) here.

For OpenNI2 installation, first install the dependencies:

sudo apt-get install git g++ python libusb-1.0-0-dev freeglut3-dev doxygen graphviz

Please note that doxygen and graphviz needs 600-ish MB to download (5 minutes at ca. 2 MByte/s), and they will take around 900MB of your SD Card space once installed. They are needed to compile the documentation. Once OpenNI2 is built, we do not need this two packages anymore (I think). So if you have limited internet speed, this step itself will take a lot of time, not to mention Raspberry Pi is very slow when it comes to package installation. As mentioned before, you can just download the pre-compiled package and it will work just fine.

Now grab a copy of OpenNI2 source code from github:

git clone

Then there are two files that needed to be altered:
First OpenNI2/ThirdParty/PSCommon/BuildSystem/Platform.Arm. Change or comment this line:

CFLAGS += -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp #-mcpu=cortex-a8

then replace or add with this:

CFLAGS += -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard

The second file is OpenNI2/Redist/ Go to line 534 to find this:

compilation_cmd = "make -j" + calc_jobs_number() + " CFG=" + configuration + " PLATFORM=" + platform + " > " + outfile + " 2>&1"

Then duplicate the line, comment the original and change the copied line:

#compilation_cmd = "make -j" + calc_jobs_number() + " CFG=" + configuration + " PLATFORM=" + platform + " > " + outfile + " 2>&1"
compilation_cmd = "make -j1" + " CFG=" + configuration + " PLATFORM=" + platform + " > " + outfile + " 2>&1"

Now let’s build OpenNI2:

cd OpenNI2/

This took ca. 30-40 minutes on my Raspberry Pi.

Then create the OpenNI2 package:

cd Redist/
./ arm

Now you can find the installer package (OpenNI-Linux-Arm-2.1.0.tar.bz2) in the folder OpenNI2/Redist/Final.

To install this package, simply unzip it to somewhere. I chose in /usr/local/src. You might need to change your group into staff so you have write permission in that folder. I’m not sure whether this is “safe” or not.

sudo usermod -a -G staff pi

Or just use sudo while copying.

cd Final/
cp OpenNI-Linux-Arm-2.1.0.tar.bz2 /usr/local/src
cd /usr/local/src/
tar -xjvf OpenNI-Linux-Arm-2.1.0.tar.bz2

Now that we have the installation package, let’s install it:

cd OpenNI-2.1.0-arm/
sudo ./

Nothing will come up if you got it right. Now you can try if it works with your Asus Xtion. First make sure it’s detected in your Raspberry Pi, check the output of lsusb -vv, it should come up somehow like this:

Bus 001 Device 006: ID 1d27:0600  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x1d27 
  idProduct          0x0600 
  bcdDevice            0.01
  iManufacturer           2 PrimeSense
  iProduct                1 PrimeSense Device
  iSerial                 0 

### DELETED ###

Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
  (Bus Powered)

If it’s giving

Bus 001 Device 006: ID 1d27:0600  
Couldn't open device, some information will be missing

unplug and plug in other USB port. My 256MB Raspberry Pi is able to detect the sensor without powered USB hub, but it couldn’t get any data out of it. Some say this is because this RPi version has lower USB bandwidth. But in Hirotaka’s website he’s connecting Xtion directly to his 512MB Raspberry Pi and it works just fine.

Then try to read the sensor data:

cd Samples/Bin

This is my output:

ariandy@raspberrypi /usr/local/src/OpenNI-2.1.0-arm/Samples/Bin $ ./SimpleRead 
Warning: USB events thread - failed to set priority. This might cause loss of data...
[00000000]     3816
[00033369]     3816
[00066738]     3816
[00100107]     3816
[00133477]     3816
[00166846]     3816
[00200215]     3816
[00233584]     3816
[00266954]     3816
[00300323]     3816

If you get the same output, you should get something nice for yourself and celebrate!

Now we just have to make an OpenCV viewer program, because the default SimpleViewer will not compile on Raspberry Pi.

To be continued …