chrooted sftp

chrooted sftp:

$ sudo adduser –shell /bin/false pietjepuk

password:

$ /home $ sudo chown root:pietjepuk /home/pietjepuk/
$ sudo chmod 755 /home/pietjepuk/

$ sudo vi /etc/ssh/sshd_config

comment de regel waar sftp server wordt bepaald:
#Subsystem sftp /usr/lib/openssh/sftp-server

En voeg het volgende onderaan toe:
Subsystem sftp internal-sftp
Match User pietjepuk
ChrootDirectory %h
ForceCommand internal-sftp
X11Forwarding no
AllowTCPForwarding no

$ sudo service ssh restart

json kladblok

http://api.jquery.com/jquery.getjson/

$.getJSON( “ajax/test.json”, function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push( “

  • ” + val + “
  • ” );
    });

    $( “

      “, {
      “class”: “my-new-list”,
      html: items.join( “” )
      }).appendTo( “body” );
      });

      http://stackoverflow.com/questions/867916/creating-a-div-element-in-jquery

      jQuery(‘

      ‘, {
      id: ‘foo’,
      href: ‘http://google.com’,
      title: ‘Become a Googler’,
      rel: ‘external’,
      text: ‘Go to Google!’
      }).appendTo(‘#mySelector’);

    bulk update with exception handling

    CREATE TABLE tmp_table (aaa VARCHAR2(100) NOT NULL);
    
    DECLARE
    
      TYPE t_varchar IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
      a_varchar t_varchar;
      e_bulk_errors             EXCEPTION;
      t_error_index             PLS_INTEGER;
      PRAGMA EXCEPTION_INIT(e_bulk_errors,-24381);
    
    BEGIN
    
      a_varchar(1) := 'aaa';
      a_varchar(2) := NULL;
      a_varchar(4) := NULL;
      a_varchar(5) := 'eee';
      a_varchar(7) := 'fff';
      a_varchar(8) := 'ggg';
      a_varchar(9) := NULL;
    
      FORALL i IN INDICES OF a_varchar SAVE EXCEPTIONS
        INSERT INTO tmp_table (aaa) VALUES (a_varchar(i)); 
    
    EXCEPTION
      WHEN e_bulk_errors
      THEN
        FOR i IN 1..SQL%bulk_exceptions.COUNT
        LOOP
          t_error_index    := SQL%BULK_EXCEPTIONS(i).error_index;
          dbms_output.put_line(i||' error code  '||SQL%BULK_EXCEPTIONS(i).error_code);
          dbms_output.put_line(i||' error index '||t_error_index);
        END LOOP;
    END;

    One drawback here is the t_error_index. That’s not the index from a_varchar, but an sequential index. So in this case the last error is raised for a_varchar(9). But sequential this is the 7th record in the plsql table. so in this case t_error_index containt number 7 and NOT 9. Be assured to have n index in a_varchar without gaps.

    timezones

    Learned something new today about timezones

    date with timezone indicator can be visualized as
    2014-01-28T10:35:08+00:00
    or
    2014-01-28T10:35:08Z

    That Z is the same as +00:00 also called Zulu timezone.

    Never have been in the military service so didn’t know about that zulu thing.

    wiki1

    wiki2

     

    undress raspbian

    My raspberry pi with 64 gig sd card running raspbian was a bit unstable. Sometimes it took 4 or 5 tries to get it booted. And it crashed once in a while. Finally I got out of this misery by stopping the dbus.

    $sudo service dbus stop

    and prevent starting it again at next boot

    $sudo update-rc.d dbus remove

    Now get rid of all the x11 “shit” let’s try

    $sudo apt-get --auto-remove --purge remove libx11*

    Before this command 702 packages where installed. Afterwards about 480 are left. But a lot of trash has been left. So with another

    $sudo apt-get autoremove

    the number of installed packages is reduced to 450. Still not everything has been removed. So:

    $dpkg -l | grep '^rc'

    shows all packages marked for purge (package has been removed, but still configuration files exist). Let’s remove them.

    $dpkg -l | grep '^rc' | cut -d" " -f3 | xargs sudo dpkg --purge

    Now I’m left with 375 packages. It’s getting better. Get rid of all dbus things (will also remove wpasupplicant and udisks.. well)

    $sudp apt-get remove libdbus*
    $sudo apt-get autoremove

    removes another 28 packages. Now remove samba

    $sudo apt-get --auto-remove --purge remove samba-common

    remove ifplugd

    $sudo apt-get --auto-remove --purge remove ifplugd

    cleanup /etc/network/interfaces till:

    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet dhcp

    Ok now rebooting the pi will take less than 30 seconds (from shutdown -r now till the device reacts on ping).

    Hmm sound what do I need that for let’s get rid of alsa:

    sudo apt-get --auto-remove --purge remove alsa-*

    and the rest:

    sudo apt-get --auto-remove --purge remove omxplayer desktop-file-utils xdg* penguinspuzzle java-common firmware*

     

    where to find c headers

    gcc lcdtest.c -Isrc/ -L./libpifacecad/ -lpifacecad -L./libmcp23s17/ -lmcp23s17 -o lcdtest

    fails into:
    lcdtest.c:1:23: fatal error: pifacecad.h: No such file or directory
    compilation terminated.

    let’s google:

    #include tells GCC to look where it finds the standard C headers, probably not where you have your header. #include “pifacecad.h tells GCC to look for headers in the current working directory.

    #include =>
    #include “pifacecad.h”

    now gcc lcdtest.c -Isrc/ -L./libpifacecad/ -lpifacecad -L./libmcp23s17/ -lmcp23s17 -o lcdtest
    works

    writing a lcd display program in c

    Let’s start with the final part: how to compile:
    gcc -c mpddispl.c -o mpddispl.o
    gcc mpddispl.o /usr/lib/libmpdclient.so -o mpddispl

    Now the beginning.

    I bought a nifty display for my raspberry pi running mpd: a piface with a display:

    pifacecadonpi

     

    Now what i want is just simple. Show the streamname and current song that is mpd playing.

    Oh and I want to make it an C excercise. Later on Python, but for now C.

    To make live a bit easier, I want to use at least 2 ‘standard’ libraries.

    1. libmpdclient for communcation with mpd

    2. libpifacecad for communication with the display (and lateron all the buttons).

    libmpdclient (and the dev version for some header info) can be installed by apt-get install libmpdclient2 libmpdclient-dev

    libpifacecad can be installed by compiling according to this page: http://piface.github.io/libpifacecad/

     

    First things first: query mpd.
    You can get lots of info from mpd. But what I want to show is some song info currently playing. Like the songtitle or the stream name.

    nfs mount point directory mess

    Had to share some very specific directories from this machine by nfs.

    So I created a new directory in root: /nfsshare

    In here I created some mount points:
    Let’s say I have this directory /var/lib/users/xxx/bla/zzz containing all documents to be shared.

    in nfshare i create a new directory zzz

    with sudo mount -o bind /var/lib/users/xxx/bla/zzz /nfsshare/zzz/ now data is accesible from /nfsshare/zzz

    so adding this direactory to /etc/exports:

    /nfsshare/zzz 192.168.1.0/24(ro,no_subtree_check)

    no on ubuntu restart nsf daemon

    sudo service nfs-kernel-server restart

    mounting this nfs share on the other machine is as simple as

    $mount -t nfs 192.168.1.116:/nfsshare/xxx /mnt/xxx

    raspbian stripping

    The raspberry pi sitting in my parents cupboard only handles some ssh and rsync stuff. I installed the default raspbian image. Now I will strip this device to a minimum bare state. This means, getting rid of all X stuff (it’s headless).

    First check some processes ($ps aux) I think not really needed

    root 1312  0.0  0.1   1744   512 ?        S    May13   0:23 /usr/sbin/ifplugd -i eth0 -q -f -u0 -d10 -w -I
    root 1340  0.0  0.1   1744   504 ?        S    May13   0:04 /usr/sbin/ifplugd -i lo -q -f -u0 -d10 -w -I
    #Brings networks interfaces up and down automatically when the cable is removed / inserted. The ethernet cable is always inserted (without this device is useless)
    $ sudo update-rc.d ifplugd remove

    ok this is a bit of a nasty one. ifplugd is also controlled by some udev-rules
    (look in /etc/default/ifplugd, it mentions /lib/udev/ifplugd.agent)

    first alter /etc/network/interfaces:
    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet dhcp

    then alter the one line in /lib/udev/rules.d/60-ifplugd.rules to
    #SUBSYSTEM==”net”, RUN+=”ifplugd.agent”

    ok network still runs. now ifplugd can be removed from the system ($sudo apt-get purge ifplugd)

    nobody 1557  0.0  0.1   2012   636 ?        Ss   10:49   0:00 /usr/sbin/thd –daemon –triggers
    /etc/triggerhappy/triggers.d/ –socket /var/run/thd.socket –pidfile /var
    #Short-Description: triggerhappy hotkey daemon
    $ sudo update-rc.d triggerhappy remove

    root 1841 0.0 0.1 2060 732 ? Ss+ May13 0:00 /sbin/getty -L ttyAMA0 115200 vt100
    #Spawn a getty on Raspberry Pi serial line
    $ vi /etc/inittab => remove or comment respawn line

    root 1773 0.0 0.7 26520 3684 ? Sl 10:49 0:00 /usr/sbin/console-kit-daemon –no-daemon
    root 1840 0.0 0.5 22320 2928 ? Sl 10:49 0:00 /usr/lib/policykit-1/polkitd –no-debug

    Mount noatime or relatime

    On my rasdpberry pi when i mount my usb disk (ext3 filesystem) just with mount /dev/sda1 /mnt/disk1 the disk gets io every 5 seconds jdbd2 shows up in iotop. So I remounted with -o noatime. Now the disk keeps quiet. Only backdraft is now files dont get a accesstime recorded. Now I read about relatime as option. Will check this tonight.