Skip to main content

chrooted SFTP

Creating chroot SFTP accounts

For $DAYJOB I had to create user accounts for customers and give them access to SFTP files to/from secured areas of our server. We wanted to use chroot functionality to ensure that no customer could see other customers' data, and prevent them from poking around potentially sensitive areas of the server. After a bit of trial-and-error, I've listed the lessons-learned here in a cook-book fashion so that in case I ever have to do it again, I have the steps documented.

This post was spurred to exist thanks to this Reddit post asking about creating an encrypted FTP server on OpenBSD so my reply there became the basis for this post.

Read more…

CLI Tricks: Spongebob Sarcasm in awk

Sometimes you want to turn some text into "sarcastic Spongebob" text so this little fragment of awk will make that transformation for you:

#!/usr/bin/awk -f
BEGIN { srand() }
{
    n = split($0, a, //)
    for (i=1; i<=n; i++) {
        c=a[i]
        printf("%c", rand() < 0.5 ? toupper(c) : tolower(c))
    }
    print ""
}
sarcasm.awk

Read more…

CLI Tricks: Full justify text with awk

I wanted to do some full-justification of text. So a little awk later, I could set the desired width and pipe to justify it.

#!/usr/bin/awk -f
BEGIN {c = "COLUMNS" in ENVIRON ? ENVIRON["COLUMNS"] : 80}
{
    if (NF > 1) {
        s = $0
        wc = split(s, a)
        gsub(FS, "", s)
        totalfill = c - length(s)
        fill = totalfill / (wc - 1)
        intfill = int(fill)
        errdelta = fill - intfill
        err = 0.5
        printf("%s", a[1])
        for (i=2; i<=length(a); i++) {
            width = intfill
            err += errdelta
            if (err >= 1) {
                ++width
                err -= 1
            }
            printf("%*s%s", width, " ", a[i])
        }
        printf("\n")
    } else print
}
full-justify.awk

Read more…

CLI Tricks: Freeze dance with cmus

Our daughter wanted to "freeze dance" (music plays, stopping at random intervals, at which the dancing kids freeze in place until the music resumes). So what is a geek dad to do? Load up a playlist of kids' music in cmus, start playing the music, and let the shell randomly freeze and resume the music

while true ; do sleep $(( $RANDOM % 15 + 5)) ; cmus-remote -u ; sleep 4; cmus-remote -u ;  done

This does as sleep for some random interval between 5 and 20 seconds, then does as sleep for 4 seconds before unpausing the music.

You could do something similar with mpd/mpc if you prefer them.