Commit 3230488b authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve add_eterkey

parent 347091c3
......@@ -23,17 +23,31 @@ VEID=$3
[ -n "$USERNAME" ] || fatal "Usage: $0 username host [VEID | -l]"
USERKEY=/home/$USERNAME/.ssh/id_dsa.pub
if [ "$USERNAME" = "root" ] ; then
USERKEY=/root/.ssh/id_dsa.pub
fi
[ -r "$USERKEY" ] || USERKEY=/home/$USERNAME/.ssh/id_rsa.pub
[ -r "$USERKEY" ] || fatal "Can't read ssh key $USERKEY"
ssh $HOST echo || fatal "Host $HOST is not sshed"
ADDKEYCMD="useradd $USERNAME ; su - $USERNAME -c 'mkdir -p ~/.ssh ; chmod 700 ~/.ssh ; touch ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys' ; cat >>/home/$USERNAME/.ssh/authorized_keys"
# FIXME: почему-то в cat не раскрывается тильда!
#ADDKEYCMD="useradd $USERNAME ; su - $USERNAME -c 'mkdir -p ~/.ssh ; chmod 700 ~/.ssh ; touch ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys' ; cat >> /home/$USERNAME/.ssh/authorized_keys"
HSSH=/home/$USERNAME/.ssh
ADDKEYCMD="useradd $USERNAME ; su - $USERNAME -c 'mkdir -p $HSSH ; chmod 700 $HSSH ; touch $HSSH/authorized_keys ; chmod 600 $HSSH/authorized_keys' ; cat >> $HSSH/authorized_keys"
# copy key in host system
if [ -z "$VEID" ] ; then
echo "Copy key for $USERNAME to $HOST"
cat $USERKEY | docmd ssh $HOST "$ADDKEYCMD"
ssh $HOST ls /home/$USERNAME/.ssh -l
#ssh -i $USERKEY $USERNAME@$HOST ls ~/.ssh -l
# TODO (.gitconfig)
# git config --global user.email "you@example.com"
# git config --global user.name "Your Name"
exit
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment