Skip to content

Instantly share code, notes, and snippets.

@vjt
Last active May 12, 2023 11:28
Show Gist options
  • Select an option

  • Save vjt/a6641c707402cc8f28c7c9d003f3c03f to your computer and use it in GitHub Desktop.

Select an option

Save vjt/a6641c707402cc8f28c7c9d003f3c03f to your computer and use it in GitHub Desktop.

Revisions

  1. vjt revised this gist Oct 12, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion 2fa
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/bin/bash

    # -*- 2fa Command Line -*-
    #
    # Uses oath-toolkit http://nongnu.org/oath-toolkit/
    # to generate 2FA OTPs and copies them in the Mac's
    # clipboard using pbcopy(1). For other UNIX systems
    # you can just strip the pbcopy at the bottom.
    #

    # In the dir below you should put TOTP token seeds,
    # one per file, naming it after the service you are
    # authenticating against.
    @@ -17,6 +17,10 @@
    # for TOTP to work, you *need* the seed, so it will
    # be hidden, somewhere, for you to find out.
    #
    # - [email protected] Thu Oct 12 22:53:11 CEST 2017
    #
    # WTFPL license (http://www.wtfpl.net/)
    #
    BASEDIR=~/Documents/2fa

    service=$1
  2. vjt revised this gist Oct 12, 2017. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion 2fa
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,22 @@
    #!/bin/bash

    #
    # Uses oath-toolkit http://nongnu.org/oath-toolkit/
    # to generate 2FA OTPs and copies them in the Mac's
    # clipboard using pbcopy(1). For other UNIX systems
    # you can just strip the pbcopy at the bottom.
    #

    # In the dir below you should put TOTP token seeds,
    # one per file, naming it after the service you are
    # authenticating against.
    #
    # Each service uses different approaches to let you
    # know (or to try to prevent you from knowing) your
    # TOTP seed: it's up to you to find it out. Anyway,
    # for TOTP to work, you *need* the seed, so it will
    # be hidden, somewhere, for you to find out.
    #
    BASEDIR=~/Documents/2fa

    service=$1
    @@ -23,5 +40,4 @@ fi

    code=$(cat $file)
    oathtool --totp -b "$code" | pbcopy

    echo "Copied to the clipboard"
  3. vjt revised this gist Oct 12, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions 2fa
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/sh
    #!/bin/bash

    BASEDIR=~/Documents/2fa

    @@ -22,8 +22,6 @@ if [ ! -f "$file" ]; then
    fi

    code=$(cat $file)


    oathtool --totp -b "$code" | pbcopy

    echo "Copied to the clipboard"
  4. vjt created this gist Oct 12, 2017.
    29 changes: 29 additions & 0 deletions 2fa
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/sh

    BASEDIR=~/Documents/2fa

    service=$1

    if [ -z "$service" ]; then
    echo "Usage: $0 <service>"
    exit 1
    fi

    if ! echo "$service" | grep -Eq '[a-zA-Z0-9]+'; then
    echo "Invalid service name: $service"
    exit 2
    fi

    file="$BASEDIR/$service"

    if [ ! -f "$file" ]; then
    echo "Unknown service: $service"
    exit 3;
    fi

    code=$(cat $file)


    oathtool --totp -b "$code" | pbcopy

    echo "Copied to the clipboard"