Skip to main content

a silhouette of a person's head and shoulders, used as a default avatar
a silhouette of a person's head and shoulders, used as a default avatar

Protect a web directory with password

    vim /path/of/your/dir/.htaccess

Paste this into:

    AuthType Basic
    AuthName "Private Dir"
    AuthUserFile /path/of/your/dir/.htpasswd
    require valid-user

Then we must create the password file /path/of/your/dir/.htpasswd.

We want to log in with the username "user", so we do this:

    htpasswd -c /path/of/your/dir/.htpasswd user

Enter a password for "user", and you're done!

a silhouette of a person's head and shoulders, used as a default avatar

Nice and useful commands

To capture the running state of the system. Start with the running processes on the system. Enter the following:

    (ps -aux; ps -auxeww; lsof) > current_procs.txt

Grab the contents of the /proc directory. Enter the following:

    tar -cvpf proc_directory.tar /proc/[0-9]*

Take a snapshot of the network state of the system. Enter the following:

    (date; uname -a; netstat -p; netstat -rn; arp -v) > network_status.txt

Take a snapshot of the currently active and kernel memory.

    dd bs=1024 < /dev/mem > mem
    dd bs=1024 < /dev/kmem > kmem

Taking a Disk Snapshot:

    dd if=/dev/hda1 bs=1024 > hda1
a silhouette of a person's head and shoulders, used as a default avatar
a silhouette of a person's head and shoulders, used as a default avatar

Install ports collection in OpenBSD

    $ cd /tmp
    $ ftp ftp://ftp.openbsd.org/pub/OpenBSD/4.0/ports.tar.gz
    $ cd /usr
    $ sudo tar xzf /tmp/ports.tar.gz

To install a package for the 4.1 release on an i386 machine off the ftp site (including dependencies), do:

    # export PKG_PATH=ftp://openbsd.ftp.fu-berlin.de/pub/OpenBSD/4.1/packages/i386
    # pkg_add name.tgz

Ports and Packages Update for an OpenBSD Release

To grab the stable branch for the 4.1 release:

    $ cd /usr/ports
    $ cvs -q -d anoncvs@openbsd.spline.de:/cvs up -r OPENBSD_4_1 -Pd
a silhouette of a person's head and shoulders, used as a default avatar

Generating passwords with Perl

DES:

    mkpasswd
      perl -e 'printf "%s\n", crypt("pass", "two-letter-salt")'

MD5:

    mkpasswd --hash=md5
    perl -e 'printf "%s\n", crypt("pass", "\$1\$6-8-letter-salt\$")'

PLAIN-MD5:

    perl -MDigest::MD5 -e 'printf "{PLAIN-MD5}%s\n", Digest::MD5::md5_hex("pass")'

DIGEST-MD5:

    perl -MDigest::MD5 -e 'printf "{DIGEST-MD5}%s\n", Digest::MD5::md5_hex("user:realm:pass")'
a silhouette of a person's head and shoulders, used as a default avatar
a silhouette of a person's head and shoulders, used as a default avatar

FreeBSD FTP tips & tricks

Q. Does anyone know if the default ftp server from FreeBSD allow me to give acces to users only for ftp, no shell access to upload files to there home directories?

A. The default ftpd will work with a little tweaking.

    touch /bin/ftpshell
    echo "/bin/ftpshell" >> /etc/shells

When you add your users, set their shell to /bin/ftpshell

    echo USERNAME >> /etc/ftpchroot

The users will be able to login via ftp and nothing else because there shell
is a crap fake shell. The ftpchroot will lock them into their home
directory very effectively.

a silhouette of a person's head and shoulders, used as a default avatar

Bandwidth management with FreeBSD (using ipfw)

You have FreeBSD installed on your server and you want to manage your bandwidth, here is a short example to start:

    ipfw add pipe 1 ip from any to 192.168.2.x out
    ipfw add pipe 2 ip from 192.168.2.x to any in
    ipfw pipe 1 config bw 10KB/s queue 10  # download speed
    ipfw pipe 2 config bw 5KB/s queue 10   # upload speed

a silhouette of a person's head and shoulders, used as a default avatar

How to clone an OpenVZ virtual machine

I need sometimes to clone a vps in an openvz environment, so here you can find three methods to do this task:

first option:

    # vzctl stop 101
    Stopping VE ...
    VE was stopped
    VE is unmounted
    # cp -r /vz/private/101 /vz/private/202
    # cp /etc/vz/conf/101.conf /etc/vz/conf/202.conf
    # vzctl start 202
    Starting VE ...
    Initializing quota ...
    VE is mounted
    Setting CPU units: 1000
    VE start in progress...

the second option:

    #mkdir /vz/private/new_VEid
    #cd /vz/private/old_VEID
    #tar cf - * | ( cd /vz/private/new_VEid tar xfp -)
    #cp old_VEID.conf new_VEID.conf

and the third option:

    # OLDVE=222 NEWVE=333 # Just an example
    # vzctl stop $OLDVE
    # mkdir /vz/root/$NEWVE
    # cp /etc/vz/conf/$OLDVE.conf /etc/vz/conf/$NEWVE.conf
    # cp -a /vz/private/$OLDVE /vz/private/$NEWVE
    # vzctl start $NEWVE; vzctl start $OLDVE