Skip to content

Instantly share code, notes, and snippets.

@allex
Created June 6, 2014 02:16
Show Gist options
  • Save allex/56a01fed5bdbd5cd5ced to your computer and use it in GitHub Desktop.
Save allex/56a01fed5bdbd5cd5ced to your computer and use it in GitHub Desktop.
#!/bin/bash
# add trust to which user?
user=$1
# user home
home=$(grep -E "^${user}:" /etc/passwd|cut -d: -f6)
# base dir
base=$2
cd $base
if [ "X${home}" != 'X' ];then
# fix perms
mkdir -p ${home}/.ssh && \
touch ${home}/.ssh/authorized_keys && \
chown -R ${user}:${user} ${home}/.ssh && \
chmod 700 ${home}/.ssh && \
echo "Fix Complete"
#modify authorized_key
cat ${home}/.ssh/authorized_keys $base/keys/* |sort -u >$base/authorized_keys && \
diff ${home}/.ssh/authorized_keys $base/authorized_keys
mv $base/authorized_keys ${home}/.ssh/authorized_keys && \
chmod 600 ${home}/.ssh/authorized_keys && \
echo "Add Complete!"
#rm -rf $base && echo "Clean Complete"
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment