#!/bin/bash

ssh_global_user="$1"
mkdir -p /etc/ssh/$ssh_global_user
cp /home/$ssh_global_user/.ssh/authorized_keys /etc/ssh/$ssh_global_user
if [ "$ssh_global_user" == "root" ]; then
	cp /$ssh_global_user/.ssh/authorized_keys /etc/ssh/$ssh_global_user
fi
chown -Rf $ssh_global_user.$ssh_global_user /etc/ssh/$ssh_global_user
chmod 644 /etc/ssh/$ssh_global_user/authorized_keys
sed -i "/AuthorizedKeysFile.*/d" /etc/ssh/sshd_config
echo "AuthorizedKeysFile    /etc/ssh/%u/authorized_keys" >> /etc/ssh/sshd_config
service ssh restart
