#!/bin/sh me=$USER if [ "$#" -lt 2 ] then echo "Usage: $0 [user] [host] " exit fi user=$1 host=$2 #check if id_rsa.pub exists if [ ! -f "$HOME/.ssh/id_rsa.pub" ] then echo Public key not exists, create it... ssh-keygen -t rsa fi scp $HOME/.ssh/id_rsa.pub $user@$host:/home/$user/ ssh $user@$host "cat /home/$user/id_rsa.pub >> /home/$user/.ssh/authorized_keys; rm /home/$user/id_rsa.pub; chmod 644 /home/$user/.ssh/authorized_keys;" ssh $user@$host "echo If you see this message without enter password, congratulations!"