Skip to content

Instantly share code, notes, and snippets.

@satouriko
Forked from kookxiang/update_ssh_keys.sh
Created July 5, 2018 03:11
Show Gist options
  • Select an option

  • Save satouriko/02525de6715e5e3622143ec651ef83a4 to your computer and use it in GitHub Desktop.

Select an option

Save satouriko/02525de6715e5e3622143ec651ef83a4 to your computer and use it in GitHub Desktop.

Revisions

  1. @kookxiang kookxiang revised this gist Jul 5, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_ssh_keys.sh
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ if ! [ -f ${TARGET_DIR}/authorized_keys ]; then
    chmod 0600 ${TARGET_DIR}/authorized_keys
    fi

    curl -sS https://api.github.com/users/kookxiang/keys | grep -Po '"key": ".+?"' | sed -e 's/\"key\": \"//' -e 's/"$//' >> ${TARGET_DIR}/authorized_keys.new
    curl -sS https://api.github.com/users/${GITHUB_USERNAME}/keys | grep -Po '"key": ".+?"' | sed -e 's/\"key\": \"//' -e 's/"$//' >> ${TARGET_DIR}/authorized_keys.new
    if [ $? != 0 ]; then exit 1; fi

    cat ${TARGET_DIR}/authorized_keys.new > ${TARGET_DIR}/authorized_keys
  2. @kookxiang kookxiang created this gist Apr 3, 2017.
    24 changes: 24 additions & 0 deletions update_ssh_keys.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env sh

    TARGET_DIR='/home/kookxiang/.ssh'
    GITHUB_USERNAME='kookxiang'

    if ! [ -d ${TARGET_DIR} ]; then
    mkdir ${TARGET_DIR}
    chmod 0700 ${TARGET_DIR}
    fi
    if ! [ -f ${TARGET_DIR}/authorized_keys ]; then
    touch ${TARGET_DIR}/authorized_keys
    chmod 0600 ${TARGET_DIR}/authorized_keys
    fi

    curl -sS https://api.github.com/users/kookxiang/keys | grep -Po '"key": ".+?"' | sed -e 's/\"key\": \"//' -e 's/"$//' >> ${TARGET_DIR}/authorized_keys.new
    if [ $? != 0 ]; then exit 1; fi

    cat ${TARGET_DIR}/authorized_keys.new > ${TARGET_DIR}/authorized_keys
    rm -rf ${TARGET_DIR}/authorized_keys.new
    echo >> ${TARGET_DIR}/authorized_keys
    if [ -f ${TARGET_DIR}/alternate_keys ]; then
    cat ${TARGET_DIR}/alternate_keys >> ${TARGET_DIR}/authorized_keys
    echo >> ${TARGET_DIR}/authorized_keys
    fi