diff options
author | Aaron LI <aly@aaronly.me> | 2018-04-18 16:41:27 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-04-18 16:44:09 +0800 |
commit | 053cd1b7fe10f746792e0d1353fad4ad04e8ebe9 (patch) | |
tree | 93137af7af0b073383e0db5ae91cbe301f9bcdd1 /roles/git/files/git-shell-commands/addkey | |
parent | f448bcbdf07cf988ab50950df95d822f359041db (diff) | |
download | ansible-dfly-vps-053cd1b7fe10f746792e0d1353fad4ad04e8ebe9.tar.bz2 |
Add git role: host git repos and share repos via cgit
* Host git repositories
* Share git repositories through web interface via cgit
* The static resources used by cgit is also managed/deployed by a git repo ^_^
Diffstat (limited to 'roles/git/files/git-shell-commands/addkey')
-rw-r--r-- | roles/git/files/git-shell-commands/addkey | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/roles/git/files/git-shell-commands/addkey b/roles/git/files/git-shell-commands/addkey new file mode 100644 index 0000000..670fd94 --- /dev/null +++ b/roles/git/files/git-shell-commands/addkey @@ -0,0 +1,49 @@ +#!/bin/sh +# +# ~/git-shell-commands/addkey +# +# An interactive command to add a new SSH public key to the authorized +# key list. To ensure the integrity of the authorized_keys file, the +# script makes sure you've entered a valid key (which must be entered +# all on one line). For security, the script also disables some SSH +# options for the key when it adds it. +# +# NOTE: +# This interactive command is NOT allowed through a SSH connection, +# use `sudo su - git` from other (admin) user instead. +# +# Credit: +# * Hosting an admin-friendly git server with git-shell +# http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell +# +# Aaron LI +# 2017-06-18 +# + +if [ -n "${SSH_CONNECTION}" ]; then + echo "Sorry, this command is not allowed through a SSH connection" + exit 1 +fi + +# Read in the SSH key +echo "Input the SSH public key to be added (ED25519/RSA):" +read key + +# Generate a fingerprint +fingerprint=$(echo "${key}" | ssh-keygen -lf -) + +# Check for errors +if [ $(echo "${fingerprint}" | egrep -c '(ED25519|RSA)') -eq 0 ]; then + # Display the fingerprint error and clean up + echo "Invalid key: ${fingerprint}" + exit 1 +fi + +# Add the key to the authorized keys file and clean up +[ ! -d "${HOME}/.ssh" ] && mkdir -m 0700 ${HOME}/.ssh +echo ${key} >> ${HOME}/.ssh/authorized_keys +chmod 0600 ${HOME}/.ssh/authorized_keys + +# Display the fingerprint for reference +echo "Success! Added a key with the following fingerprint:" +echo ${fingerprint} |