söndag 23 november 2008

sshfs mount in etc/fstab without password

To mount a directory via sshfs in fstab, I found no instruction that worked for me on an ubuntu 8.04 installation.
I have created a user which is allowed to log in only via sftp to my server, and I now wanted a directory on the server being visible readonly on my client, mounted over sftp to maintain ease of configuration and high security. Fuzzing around with smbfs, nfs or something else seemed like a bad idea as I want the same solution to work also over internet, where the only entrance hole through my server is via ssh anyway.

Setup the server so it is possible to sftp to it. See my previous post. I call this user romusic. The server is at 192.168.0.10 below. I carry out commands in a root shell (typing sudo is not my thing, really) by issuing "sudo su - " in the beginning.

Setup passwordless ssh login (see any of the million posts on this if you need more info).
$ssh-keygen
Copy the contents of the generated .pub key into ~/.ssh/authorized_keys on the server. Copy the private key to /root/id_rsa_romusic

make sure sshfs works as a user (using a password here)
$sshfs romusic@192.168.0.10:musik/ musik/

To be able to pass the identity file to ssh via sshfs we have to make a wrapper. This step is what is not covered in the posts I found on the subject. That is because I could not pass "ssh -i id_rsa" as ssh executable to sshfs, this made it complain over execvp. Here is the workaround:
Create the file /root/ssh_i_romusic.sh
#!/bin/sh
/usr/bin/ssh -c arcfour -i /root/id_rsa_romusic $@

Note that I also use cipher arcfour to speed things up here, this should be avoided unless you trust your network somewhat. Just leave it out if you do not know what it means or if you are on a potentially untrusted network.
Do not forget to set that file owned by root:root and it is executable and not writable.

Create a mount point
$mkdir /mnt/musik

Make sure you can mount (this is also needed to accept the key id, needed only once)
$sshfs romusic@192.168.0.10:musik/ /mnt/musik/ -o allow_other,uid=0,gid=0,reconnect,umask=222,sshfs_debug,sshfs_debug,"ssh_command=/root/ssh_i_romusic.sh"

I accepted the key and everything went fine. I now umount and then head for /etc/fstab to make it mount automagically.
$fusermount -u -z /mnt/musik

my fstab entry:
sshfs#romusic@192.168.0.10:musik/ /mnt/musik/ fuse ro,allow_other,uid=0,gid=0,reconnect,umask=222,sshfs_debug,sshfs_debug,ssh_command=/root/ssh_i_romusic.sh 0 0

Make sure everything works by
mount -a
and see there are no complaints.
After that, /mnt/musik should be readable.

torsdag 20 november 2008

sftp med minsta möjliga rättigheter

FTP är krångligt att sätta upp bakom en brandvägg. Dessutom verkar många ha väldigt svårt för att använda ftp-program. Därtill är ftp okrypterat.
Ett bra alternativ är sftp (notera skillnaden mot ftps).

Att sätta upp en sftp-server är lika lätt som att installera en sshserver, i debian (och ubuntu?) är det bara att installera packetet openssh-server så är det klart.
Däremot krävs det en del extra för att kunna ha användare som har tillgång till sftp men inte ett normalt shellkonto.

Jag följde guiden här, men det är ganska lätt bara man kommer ihåg följande steg:
  1. skapa gruppen sftponly: $addgroup sftponly
  2. konfigurera sshd (filen /etc/ssh/sshd_conf) så att en avdelning med "match group sftponly..." finns med innehåll
    Match group sftponly
    ChrootDirectory /home/%u
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp
    Glöm inte heller att ändra
    Subsystem sftp /usr/lib/openssh/sftp-server
    till
    Subsystem sftp internal-sftp
  3. ladda om konfigurationen med $/etc/init.d/ssh reload
  4. skapa en användare du vill ska kunna enbart använda sftp: $adduser unlucky
  5. tilldela gruppgemenskap: $addgroup unlucky sftponly
  6. sätt hemkatalog till / : $usermod -d / unlucky
  7. se till att hemkatalogen ägs av root (för att ssh-servern ska kunna göra chroot): $chown root:root /home/unlucky
  8. se till att användaren inte kan logga in normalt: $chsh -s /bin/false unlucky
Prova sedan att logga in med den nya användaren. Det ska inte gå vare sig direkt, via ssh, via su - unlucky utan enbart via sftp.
För windows finns winscp och filezilla som går att ansluta sig med.

Jag monterar kataloger inuti /home/unlucky med --bind readonly så att den nya användaren kan läsa men inte skriva. Mer om det någon annan dag!

onsdag 19 november 2008

Avdelare för signatur i epost

Något som många(sett till antal användare) epostprogram verkar ha missat är att det finns en praxis för hur man markerar att meddelandet är slut och en signatur börjar. Praxis finns att läsa här: RFC3676, kapitel 4.3.

Om man följer praxis kan emailkonversationer (ni vet, alla det där mailen med ämnesrad "RE:SV:FW:RE:FW:FW bla") bli avsevärt mer läsbara eftersom man slipper läsa allas signaturer insprängda mitt i meddelandena.

Om ditt epostprogram inte avdelar signaturen enligt praxis, lägg då själv in två streck och ett mellanslag på en ensam rad i toppen av din signatur.

tisdag 11 november 2008

Compile realtime kernel in Debian lenny (preemption patch)

This is how to compile a realtime kernel (preemptive kernel) in Debian Lenny. It should pretty much be cut and paste. I run a 64 bit Intel Q6600 system on a standard pc, and had a bit of hazzle before I got latencies down to a reasonable level.
I will use the directory /var/tmp/KERNEL to build in but that is not important.
  • become root
  • mkdir /var/tmp/KERNEL
  • cd /var/tmp/KERNEL
  • wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.6.tar.bz2
  • wget
    http://www.kernel.org/pub/linux/kernel/projects/rt/patch-2.6.26.6-rt11.bz2
  • tar xvjf linux-2.6.26.6.tar.bz2
  • cd linux-2.6.26.6
  • bzcat ../patch-2.6.26.6-rt11.bz2 |patch -p1
  • make clean && make mrproper
  • make menuconfig (select complete preemption, choose 1000 Hz timer frequency. High resolution timers and symmetric multiprocessing SMP were already enabled)
  • make-kpkg clean
  • fakeroot make-kpkg --initrd --append-to-version=-rt-200811111930 kernel_image kernel_headers
  • dpkg -i ../linux-headers-2.6.26.6-rt11-rt-200811111930_2.6.26.6-rt11-rt-200811111930-10.00.Custom_amd64.deb ../linux-image-2.6.26.6-rt11-rt-200811111930_2.6.26.6-rt11-rt-200811111930-10.00.Custom_amd64.deb
To make sure everything works as intended, run cyclictest (see previous post here) and make sure the latencies are low. I get approximately 300 us max latency which is a bit high compared to other results I have seen, but low enough for me. Make sure you stress the computer when running the test. Without the preemption patch, I get 3000 us in latency when I open a web browser. I also had to turn off things in the bios to get down to 300 us.
I tried the ubuntu realtime kernel 2.6.24 which installs fine on debian lenny, but the latency would just not come down. This indicates the BIOS setting was the crook. I use noapic nolapic as boot settings, which seem to be needed.

Update 2008-11-12:
The frequency scaling is the crook! Running a preemptive kernel as compiled above works fine until the cpu frequency jumps. It has nothing to do with noapic or nolapic, it is sufficient to prevent the frequency to change. You can do this with either disabling frequency scaling in BIOS, or lock the frequency with
for i in `seq 0 3`; do cpufreq-set -c$i -g performance; done
to get constant full speed or
for i in `seq 0 3`; do cpufreq-set -c$i -g powersave; done

to get lowest speed. Both work fine and gets the latency down to 250 us (performance ) to 20 us (powersave) when I tested, as compared to 3000 us with ondemand frequncy scaling governor. I guess I should test with heavier load and longer time to be sure, but I am confident that the frequency scaling is the one to blame. To bad, because frequency scaling is a wonderful thing.
I tried to keep only one core constant speed and locking the processes to that core with taskset
echo `seq 6050 6056` |xargs -n1 taskset -p 0x1

where 6050 is the process id reported by cyclictest.

fredag 7 november 2008

Kompilera cyclictest

Jag experimenterar med realtidslinux i form av standard linux med patchar för preemption (se rt wiki).
Såhär gör man för att köra cyclictest:
git-clone git://git.kernel.org/pub/scm/linux/kernel/git/tglx/rt-tests.git \ rt-test
cd rt-test
make
./cyclictest -p 20 -t5 -n

(som root, eller med sudo framför om man kör t ex ubuntu)

måndag 3 november 2008

Handelsöverskott, dollarn

Jag fick ett tips(tack A!) om att se iousa, en film om USA:s finansiella situation.
Mycket intressant. Att dollarn är stark verkar vara omotiverat om man tittar på tillståndet i den amerikanska ekonomin. En aning trist eftersom jag just ska betala ett stort belopp i dollar.
Hursom, mitt i fanns en lista med handelsunderskott (om jag förstått saken rätt). Den försvann förbi väldigt fort så jag letade efter statistik och hittade följande:
handelsöverskott enligt IMF
IMF:s databas har ett mycket bra användargränssnitt! Ett föredöme för att göra data tillgängligt
För 2008:
Sverige ligger på 16:e plats i handelsöverskott med 32 miljarder USD. Kina ligger etta med 386 miljarder USD, medan USA är ohotad på botten med ett handelsunderskott på 615 miljarder USD.
Mycket intressant. Ekonomi är fascinerande!