#!/bin/bash USERNAME=$1 HOME_DIR=$(grep ^$USERNAME /etc/passwd | cut -f6 -d:) if [ ! -d $HOME_DIR/.ssh ]; then mkdir -p $HOME_DIR/.ssh chmod 0700 $HOME_DIR/.ssh fi if [ ! -e $HOME_DIR/.ssh/authorized_keys ]; then touch $HOME_DIR/.ssh/authorized_keys chmod 0600 $HOME_DIR/.ssh/authorized_keys fi if ! grep -q "$2" $HOME_DIR/.ssh/authorized_keys; then echo "$2" >> $HOME_DIR/.ssh/authorized_keys fi chown -R $USERNAME $HOME_DIR/.ssh